forge
Explore
Log in

Don't you dare go Hollow

Reduced_tx_set=0 -- the wider tx_type alphabets, off by default

Browse files at this commit

e6bf93689cf89d64ead6d5939e6a42ad88755d7eAhmet Kaan GümüşParent: c29f173
  • feat
    • reduced_tx_set=0 -- the wider tx_type alphabets, off by default
Show full message
feat(av1): reduced_tx_set=0 -- the wider tx_type alphabets, off by default

The writer reads the frame's own header bit in ONE place (Cdfs::txb widens
every luma set through TxbSet::wide, transcribed from the decoder's map), the
search names the widened set so its pricer costs the same alphabet, and the
candidate lists gain the seven-type intra set and the shared seven of the
twelve/sixteen-type inter ones. speed::WIDE_TX_SET is false at every preset
(EC_AV1_TXSET_WIDE overrides), and EC_AV1_TXSET=all lifts the intra search's
screen gate for the unconditional arm the gate measures.
crates/ec-av1/src/cdf_state.rsmodified+39 -0
@@ -318,11 +318,48 @@ impl TxbSet {
318318 | Self::ChromaRect32x16
319319 )
320320 }
321+
322+ /// lane-txi: this set's `reduced_tx_set == 0` counterpart -- the WIDER
323+ /// `tx_type` alphabet the same coefficient tables are read with when the
324+ /// frame header's bit is off. Every pair here is the one
325+ /// `decode::txbset_for`/`txbset_for_inter`/`inter_txbset_for` resolve off
326+ /// that bit, transcribed from the DECODER's own map so writer and reader
327+ /// cannot drift (class `table-and-reader-move-together`); a set with no
328+ /// counterpart -- intra 16x16 and 32x32, inter 32x32, 64x64, every
329+ /// chroma set -- is its own, and widening an already-wide set is the
330+ /// identity.
331+ pub(crate) fn wide(self) -> Self {
332+ match self {
333+ Self::Luma8 => Self::Luma8Set1,
334+ Self::Luma4 => Self::Luma4Set1,
335+ Self::Luma16Inter => Self::Luma16InterSet1,
336+ Self::Luma8Inter => Self::Luma8InterSet1,
337+ Self::Luma4Inter => Self::Luma4InterSet1,
338+ Self::LumaRect16x8 => Self::LumaRect16x8Set1,
339+ Self::LumaRect4x8 => Self::LumaRect4x8Set1,
340+ Self::LumaRect16x4 => Self::LumaRect16x4Set1,
341+ Self::LumaRect16x8Inter => Self::LumaRect16x8InterSet1,
342+ Self::LumaRect8x4Inter => Self::LumaRect8x4InterSet1,
343+ Self::LumaRect16x4Inter => Self::LumaRect16x4Inter1,
344+ other => other,
345+ }
346+ }
321347 }
322348
323349 /// Every table a key frame's tile writer adapts.
324350 #[derive(Clone)]
325351 pub(crate) struct Cdfs {
352+ /// lane-txi: this FRAME's `reduced_tx_set` header bit (spec 5.9.2).
353+ /// `true` -- the default, and what every stream this encoder wrote
354+ /// before the lane carries -- leaves [`Self::txb`]'s luma set exactly as
355+ /// its caller named it. `false` widens it to the `Set1` counterpart
356+ /// ([`TxbSet::wide`]), which is the ONE place the writer and its pricer
357+ /// read the bit from, so a site that forgets it cannot code the right
358+ /// value against the wrong CDF (class `wrong-alphabet-same-value`).
359+ /// The DECODER never sets this: it names the widened set itself off the
360+ /// header (`decode::txbset_for`), and widening an already-wide set is the
361+ /// identity.
362+ pub reduced_tx_set: bool,
326363 /// The coefficient q-context these tables were built for (spec 8.3.2's
327364 /// `Get_Qctx`), so a writer can price a block against the same tables the
328365 /// search did (`tile::coeff_bits`).
@@ -996,6 +1033,7 @@ impl Cdfs {
9961033 /// quantizer, so they are the same for every `q_ctx`.
9971034 pub fn new(q_ctx: usize) -> Cdfs {
9981035 Cdfs {
1036+ reduced_tx_set: true,
9991037 q_ctx,
10001038 partition_w128: cdf::PARTITION_W128,
10011039 partition_w64: cdf::PARTITION_W64,
@@ -1602,6 +1640,7 @@ impl Cdfs {
16021640
16031641 /// The tables one table set is coded with, borrowed out of the state.
16041642 pub fn txb(&mut self, set: TxbSet, mode: usize) -> TxbTables<'_> {
1643+ let set = if self.reduced_tx_set { set } else { set.wide() };
16051644 match set {
16061645 TxbSet::Luma32 => TxbTables {
16071646 side: 32,
crates/ec-av1/src/encode.rsmodified+122 -17
@@ -273,6 +273,15 @@ fn tx_select_inter() -> bool {
273273 /// here.
274274 pub(crate) fn tx_type_candidates(set: TxbSet, screen: bool) -> &'static [TxType] {
275275 const DCT: [TxType; 1] = [TxType::DctDct];
276+ const INTRA1: [TxType; 7] = [
277+ TxType::DctDct,
278+ TxType::AdstAdst,
279+ TxType::AdstDct,
280+ TxType::DctAdst,
281+ TxType::Idtx,
282+ TxType::VDct,
283+ TxType::HDct,
284+ ];
276285 const INTRA2: [TxType; 5] = [
277286 TxType::DctDct,
278287 TxType::AdstAdst,
@@ -281,7 +290,21 @@ pub(crate) fn tx_type_candidates(set: TxbSet, screen: bool) -> &'static [TxType]
281290 TxType::Idtx,
282291 ];
283292 match set {
284- TxbSet::Luma16 | TxbSet::Luma8 | TxbSet::Luma4 if screen && tx_type_search() => &INTRA2,
293+ TxbSet::Luma16 | TxbSet::Luma8 | TxbSet::Luma4
294+ if (screen || intra_tx_all_frames()) && tx_type_search() =>
295+ {
296+ &INTRA2
297+ }
298+ // lane-txi: a `reduced_tx_set == 0` frame's intra 8x8/4x4 reads the
299+ // SEVEN-type `TX_SET_INTRA_1` (`decode::txbset_for`'s `Luma{8,4}Set1`;
300+ // 16x16 stays `TX_SET_INTRA_2`, there is no `Luma16Set1`). The two
301+ // extra members are the 1-D DCTs, and the order is the reader's own
302+ // map (`decode::tx_type_from_symbol`, 8-wide CDF).
303+ TxbSet::Luma8Set1 | TxbSet::Luma4Set1
304+ if (screen || intra_tx_all_frames()) && tx_type_search() =>
305+ {
306+ &INTRA1
307+ }
285308 _ => &DCT,
286309 }
287310 }
@@ -308,6 +331,15 @@ pub(crate) fn tx_type_candidates(set: TxbSet, screen: bool) -> &'static [TxType]
308331 pub(crate) fn inter_tx_type_candidates(set: TxbSet, screen: bool) -> &'static [TxType] {
309332 const DCT: [TxType; 1] = [TxType::DctDct];
310333 const INTER3: [TxType; 2] = [TxType::DctDct, TxType::Idtx];
334+ const INTER_WIDE: [TxType; 7] = [
335+ TxType::DctDct,
336+ TxType::AdstAdst,
337+ TxType::AdstDct,
338+ TxType::DctAdst,
339+ TxType::Idtx,
340+ TxType::VDct,
341+ TxType::HDct,
342+ ];
311343 let mode = inter_tx_type_search();
312344 let on = match mode {
313345 InterTxSearch::Off => false,
@@ -317,10 +349,56 @@ pub(crate) fn inter_tx_type_candidates(set: TxbSet, screen: bool) -> &'static [T
317349 match set {
318350 TxbSet::Luma32Inter if on && mode != InterTxSearch::Le16 => &INTER3,
319351 TxbSet::Luma16Inter | TxbSet::Luma8Inter | TxbSet::Luma4Inter if on => &INTER3,
352+ // lane-txi: a `reduced_tx_set == 0` frame's inter 16x16 reads the
353+ // TWELVE-type `TX_SET_INTER_2` and its 8x8/4x4 `ALL16` (inter 32x32
354+ // stays the two-type `DCT_IDTX`). The seven offered here are the
355+ // members those two alphabets SHARE with the intra set -- the four
356+ // DTT combinations, `IDTX` and the two 1-D DCTs -- which is the
357+ // candidate list rav1e's speed 6 prunes to; the FLIPADST family and
358+ // the 1-D ADSTs are codable and left unoffered (deferred).
359+ TxbSet::Luma16InterSet1 | TxbSet::Luma8InterSet1 | TxbSet::Luma4InterSet1 if on => {
360+ &INTER_WIDE
361+ }
320362 _ => &DCT,
321363 }
322364 }
323365
366+/// lane-txi: does THIS frame code `reduced_tx_set = 0` (spec 5.9.2), i.e.
367+/// the wider `tx_type` alphabets at intra 8x8/4x4 and inter 16x16 and below?
368+/// `EC_AV1_TXSET_WIDE`: `0`/`off`, `screen` (screen frames only), anything
369+/// else every frame; unset takes [`crate::speed::WIDE_TX_SET`], screen-gated
370+/// like both halves of the type search itself.
371+pub(crate) fn wide_tx_set(screen: bool) -> bool {
372+ static ENV: std::sync::LazyLock<Option<InterTxSearch>> = std::sync::LazyLock::new(|| {
373+ crate::envflags::var("EC_AV1_TXSET_WIDE").ok().map(|v| match v.as_str() {
374+ "0" | "off" => InterTxSearch::Off,
375+ "screen" => InterTxSearch::Screen,
376+ _ => InterTxSearch::All,
377+ })
378+ });
379+ match ENV.unwrap_or(if crate::speed::at(&crate::speed::WIDE_TX_SET) {
380+ InterTxSearch::Screen
381+ } else {
382+ InterTxSearch::Off
383+ }) {
384+ InterTxSearch::Off => false,
385+ InterTxSearch::Screen => screen,
386+ _ => true,
387+ }
388+}
389+
390+/// The luma [`TxbSet`] the SEARCH and its pricer name for a frame that codes
391+/// `reduced_tx_set = 0`: the writer reads the bit once, off the frame's own
392+/// [`crate::cdf_state::Cdfs`], but the trial that prices a type has to read
393+/// the same alphabet or the two disagree on what a `tx_type` symbol costs.
394+pub(crate) fn luma_set_for(set: TxbSet, screen: bool) -> TxbSet {
395+ if wide_tx_set(screen) {
396+ set.wide()
397+ } else {
398+ set
399+ }
400+}
401+
324402 #[derive(Clone, Copy, PartialEq)]
325403 pub(crate) enum InterTxSearch {
326404 Off,
@@ -372,14 +450,14 @@ fn inter_tx_type_search() -> InterTxSearch {
372450
373451 /// The inter luma [`TxbSet`] a `tx`-sided transform unit reads, `None` for the
374452 /// 64-point one (it codes no `tx_type` symbol).
375-fn inter_luma_set(tx: usize) -> Option<TxbSet> {
376- Some(match tx {
453+fn inter_luma_set(tx: usize, screen: bool) -> Option<TxbSet> {
454+ Some(luma_set_for(match tx {
377455 4 => TxbSet::Luma4Inter,
378456 8 => TxbSet::Luma8Inter,
379457 16 => TxbSet::Luma16Inter,
380458 32 => TxbSet::Luma32Inter,
381459 _ => return None,
382- })
460+ }, screen))
383461 }
384462
385463 fn tx_type_search() -> bool {
@@ -391,6 +469,17 @@ fn tx_type_search() -> bool {
391469 ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::TX_TYPE_SEARCH))
392470 }
393471
472+/// lane-txi: `EC_AV1_TXSET=all` offers the five-type intra set on EVERY
473+/// frame -- the unconditional arm the gate measures -- instead of the screen
474+/// content gate [`tx_type_candidates`] ships behind. Any other value keeps
475+/// the gate (`0`/`off` still switches the search off entirely).
476+fn intra_tx_all_frames() -> bool {
477+ static ENV: std::sync::LazyLock<bool> = std::sync::LazyLock::new(|| {
478+ crate::envflags::var("EC_AV1_TXSET").is_ok_and(|v| v == "all")
479+ });
480+ *ENV
481+}
482+
394483 fn tx_select() -> bool {
395484 static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| {
396485 crate::envflags::var("EC_AV1_TX_SELECT")
@@ -2536,12 +2625,15 @@ impl Plane<'_> {
25362625 let At { x, y, side, reach, .. } = at;
25372626 let tx = side >> depth;
25382627 let n = 1usize << depth;
2539- let set = match tx {
2540- 32 => TxbSet::Luma32,
2541- 16 => TxbSet::Luma16,
2542- 8 => TxbSet::Luma8,
2543- _ => TxbSet::Luma4,
2544- };
2628+ let set = luma_set_for(
2629+ match tx {
2630+ 32 => TxbSet::Luma32,
2631+ 16 => TxbSet::Luma16,
2632+ 8 => TxbSet::Luma8,
2633+ _ => TxbSet::Luma4,
2634+ },
2635+ search.screen,
2636+ );
25452637 let mut levels = vec![0i32; side * side];
25462638 census_add(4, n * n);
25472639 // A unit smaller than its block reads the neighbour magnitude table
@@ -4084,7 +4176,7 @@ fn commit_inter_luma(
40844176 let mut flat_typed: Option<Trial> = None;
40854177 let mut flat_type = TxType::DctDct;
40864178 if !skip {
4087- if let Some(fset) = inter_luma_set(side) {
4179+ if let Some(fset) = inter_luma_set(side, search.screen) {
40884180 let lambda = search.lambda * tx_type_lambda_mult();
40894181 let cost = |t: &Trial| t.sse + lambda * t.bits;
40904182 for &tx_type in inter_tx_type_candidates(fset, search.screen) {
@@ -4130,7 +4222,7 @@ fn commit_inter_luma(
41304222 // differently-predicted baseline is what would let a candidate win on
41314223 // both terms at once (class `local-rd-on-references` vs a real
41324224 // pricing defect); re-predicting it here is the only way to tell.
4133- if let Some(fset) = inter_luma_set(side) {
4225+ if let Some(fset) = inter_luma_set(side, search.screen) {
41344226 let here = match second {
41354227 Some((mv1, ref1)) => mc_trial_compound_typed(
41364228 luma, x, y, side, (mv, mv1), true, reference, ref1, search.base_q_idx,
@@ -4175,14 +4267,14 @@ fn commit_inter_luma(
41754267 return (flat_ref.levels.clone(), 0, flat_gain, vec![flat_type]);
41764268 }
41774269 let tx = side / 2;
4178- let set = if tx >= 32 {
4270+ let set = luma_set_for(if tx >= 32 {
41794271 // lane-b64b: the 64x64 root's halved transform is TX_32X32.
41804272 TxbSet::Luma32Inter
41814273 } else if tx >= 16 {
41824274 TxbSet::Luma16Inter
41834275 } else {
41844276 TxbSet::Luma8Inter
4185- };
4277+ }, search.screen);
41864278 let mut levels = vec![0i32; side * side];
41874279 let (mut sse, mut bits) = (0.0, 0.0);
41884280 let mut units = Vec::with_capacity(4);
@@ -4830,7 +4922,7 @@ fn code_square(
48304922 y,
48314923 side,
48324924 reach: Reach::of(side, x, y, luma.true_width, luma.true_height, fctx),
4833- set: luma_set,
4925+ set: luma_set_for(luma_set, search.screen),
48344926 };
48354927 let (mut luma_coeffs, mode, angle_delta, mut cost, tx_type) =
48364928 luma.search_block(at, search, mode_bits, fctx);
@@ -7118,6 +7210,9 @@ pub(crate) fn encode_key_frame_inner(
71187210 IBC_SHARE.with(|c| c.set(ibc_share));
71197211 let (seq, mut header) = key_frame_headers_colour(render.0, render.1, base_q_idx, color_config)?;
71207212 header.allow_screen_content_tools = screen;
7213+ // lane-txi: the wider `tx_type` alphabets, gated by the same content
7214+ // rule the type search itself stands behind ([`wide_tx_set`]).
7215+ header.reduced_tx_set = !wide_tx_set(screen);
71217216 header.allow_intrabc = allow_intrabc;
71227217 header.render_width = render.0 as u32;
71237218 header.render_height = render.1 as u32;
@@ -7556,7 +7651,10 @@ pub(crate) fn encode_key_frame_inner(
75567651 // defaults again (spec 7.20's `started_from` arm) -- the first inter
75577652 // frame after it therefore starts from the defaults too.
75587653 let (mi_cols, mi_rows) = (header.mi_cols, header.mi_rows);
7559- let cdfs = crate::cdf_state::Cdfs::new(crate::tile::q_ctx_of(base_q_idx));
7654+ let mut cdfs = crate::cdf_state::Cdfs::new(crate::tile::q_ctx_of(base_q_idx));
7655+ // lane-txi: the ONE place the writer reads the frame's `reduced_tx_set`
7656+ // from -- `Cdfs::txb` widens every luma set under it.
7657+ cdfs.reduced_tx_set = header.reduced_tx_set;
75607658 let start_cdfs = CdfSnapshot(cdfs);
75617659 // The luma restoration-unit grid this frame's `lr_params` implies
75627660 // (`av1_lr_count_units` rounds to nearest, so a short last unit is
@@ -10448,6 +10546,9 @@ pub(crate) fn encode_inter_frame(
1044810546 let screen = seq_screen()
1044910547 && screen_content(&picture_y8, picture.width, true_width, true_height);
1045010548 header.allow_screen_content_tools = screen;
10549+ // lane-txi, as on the key frame: the header bit the writer's own
10550+ // `Cdfs` then reads for every luma `tx_type` symbol.
10551+ header.reduced_tx_set = !wide_tx_set(screen);
1045110552 // The search prices coefficients against the tables this frame's writer
1045210553 // starts from, not against the defaults (lane-av1txbits) -- but only on a
1045310554 // frame the screen detector said no to (lane-av1price2): armed HERE, after
@@ -11272,9 +11373,13 @@ pub(crate) fn encode_inter_frame(
1127211373 // next frame's writer starts from them -- exactly what
1127311374 // `crate::stream::stored_cdfs_for` hands the decoder.
1127411375 let (mi_cols, mi_rows) = (header.mi_cols, header.mi_rows);
11275- let cdfs = start_cdfs
11376+ let mut cdfs = start_cdfs
1127611377 .cloned()
1127711378 .unwrap_or_else(|| crate::cdf_state::Cdfs::new(crate::tile::q_ctx_of(base_q_idx)));
11379+ // lane-txi: set per frame, never inherited from the snapshot the
11380+ // previous frame stored -- the content gate can flip the bit between
11381+ // frames (class `per-tile-state-not-reset`).
11382+ cdfs.reduced_tx_set = header.reduced_tx_set;
1127811383 let start_cdfs = CdfSnapshot(cdfs);
1127911384 let reference_select_bit = header.reference_select;
1128011385 let switchable_motion_mode = header.is_motion_mode_switchable;
crates/ec-av1/src/speed.rsmodified+9 -0
@@ -512,6 +512,15 @@ pub(crate) const TX_TYPE_SEARCH_INTER: [bool; 11] = [
512512 true, true, true, true, true, true, true, false, false, false, false,
513513 ];
514514
515+/// `encode::wide_tx_set`: whether a frame codes `reduced_tx_set = 0`, the
516+/// wider `tx_type` alphabets (intra 8x8/4x4 seven types, inter 16x16 twelve,
517+/// inter 8x8/4x4 sixteen) instead of the reduced sets every stream this
518+/// encoder wrote before lane-txi carries. OFF at every preset until the gate
519+/// says otherwise; `EC_AV1_TXSET_WIDE` overrides.
520+pub(crate) const WIDE_TX_SET: [bool; 11] = [
521+ false, false, false, false, false, false, false, false, false, false, false,
522+];
523+
515524 /// `filter_search`: whether the deblock ladder's +-1/+-2 refinement stage runs.
516525 pub(crate) const DEBLOCK_REFINE: [bool; 11] = [
517526 true, true, true, true, true, true, true, false, false, false, false,