Merge branch 'lane-txi' (1a5427d2): the wider transform alphabets (reduced_tx_set=0) wired off; a non-DCT rate surcharge; the trial decode had hard-coded reduced_tx_set
Browse files at this commit6 changed files +565 -13
- crates/ec-av1/src/cdf_state.rs +39 -0
- crates/ec-av1/src/decode.rs +16 -1
- crates/ec-av1/src/encode.rs +209 -12
- crates/ec-av1/src/encoder.rs +118 -0
- crates/ec-av1/src/speed.rs +9 -0
- lanes/txi.report.md +174 -0
crates/ec-av1/src/cdf_state.rsmodified+39 -0
| @@ -318,11 +318,48 @@ impl TxbSet { | |||
| 318 | | Self::ChromaRect32x16 | 318 | | Self::ChromaRect32x16 |
| 319 | ) | 319 | ) |
| 320 | } | 320 | } |
| 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 | + } | ||
| 321 | } | 347 | } |
| 322 | 348 | ||
| 323 | /// Every table a key frame's tile writer adapts. | 349 | /// Every table a key frame's tile writer adapts. |
| 324 | #[derive(Clone)] | 350 | #[derive(Clone)] |
| 325 | pub(crate) struct Cdfs { | 351 | 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, | ||
| 326 | /// The coefficient q-context these tables were built for (spec 8.3.2's | 363 | /// The coefficient q-context these tables were built for (spec 8.3.2's |
| 327 | /// `Get_Qctx`), so a writer can price a block against the same tables the | 364 | /// `Get_Qctx`), so a writer can price a block against the same tables the |
| 328 | /// search did (`tile::coeff_bits`). | 365 | /// search did (`tile::coeff_bits`). |
| @@ -996,6 +1033,7 @@ impl Cdfs { | |||
| 996 | /// quantizer, so they are the same for every `q_ctx`. | 1033 | /// quantizer, so they are the same for every `q_ctx`. |
| 997 | pub fn new(q_ctx: usize) -> Cdfs { | 1034 | pub fn new(q_ctx: usize) -> Cdfs { |
| 998 | Cdfs { | 1035 | Cdfs { |
| 1036 | + reduced_tx_set: true, | ||
| 999 | q_ctx, | 1037 | q_ctx, |
| 1000 | partition_w128: cdf::PARTITION_W128, | 1038 | partition_w128: cdf::PARTITION_W128, |
| 1001 | partition_w64: cdf::PARTITION_W64, | 1039 | partition_w64: cdf::PARTITION_W64, |
| @@ -1602,6 +1640,7 @@ impl Cdfs { | |||
| 1602 | 1640 | ||
| 1603 | /// The tables one table set is coded with, borrowed out of the state. | 1641 | /// The tables one table set is coded with, borrowed out of the state. |
| 1604 | pub fn txb(&mut self, set: TxbSet, mode: usize) -> TxbTables<'_> { | 1642 | pub fn txb(&mut self, set: TxbSet, mode: usize) -> TxbTables<'_> { |
| 1643 | + let set = if self.reduced_tx_set { set } else { set.wide() }; | ||
| 1605 | match set { | 1644 | match set { |
| 1606 | TxbSet::Luma32 => TxbTables { | 1645 | TxbSet::Luma32 => TxbTables { |
| 1607 | side: 32, | 1646 | side: 32, |
crates/ec-av1/src/decode.rsmodified+16 -1
| @@ -24891,6 +24891,12 @@ impl<'p> RefPix<'p> { | |||
| 24891 | /// (lane-defer8). | 24891 | /// (lane-defer8). |
| 24892 | fn ref_dims(ref_frame: i8, refpix: &RefPix<'_>) -> Result<(usize, usize)> { | 24892 | fn ref_dims(ref_frame: i8, refpix: &RefPix<'_>) -> Result<(usize, usize)> { |
| 24893 | refpix.dims(ref_frame).ok_or_else(|| { | 24893 | refpix.dims(ref_frame).ok_or_else(|| { |
| 24894 | + if crate::envflags::env_flag!("EC_AV1_REFPROBE") { | ||
| 24895 | + eprintln!( | ||
| 24896 | + "EC_REFPROBE missing ref {ref_frame}\n{}", | ||
| 24897 | + std::backtrace::Backtrace::force_capture() | ||
| 24898 | + ); | ||
| 24899 | + } | ||
| 24894 | unsupported( | 24900 | unsupported( |
| 24895 | "a reference frame selected with no picture at this frame's own \ | 24901 | "a reference frame selected with no picture at this frame's own \ |
| 24896 | ref_frame_idx slot for it", | 24902 | ref_frame_idx slot for it", |
| @@ -34220,6 +34226,9 @@ pub(crate) fn decode_inter_frame_tile_lr( | |||
| 34220 | interp_fixed, | 34226 | interp_fixed, |
| 34221 | enable_dual_filter, | 34227 | enable_dual_filter, |
| 34222 | reference_select, | 34228 | reference_select, |
| 34229 | + // lane-txi: this wrapper's callers are the decoder's own tests, which | ||
| 34230 | + // all code the reduced sets. | ||
| 34231 | + true, | ||
| 34223 | tx_select, | 34232 | tx_select, |
| 34224 | lr, | 34233 | lr, |
| 34225 | initial_cdfs, | 34234 | initial_cdfs, |
| @@ -34252,6 +34261,12 @@ pub(crate) fn decode_inter_frame_tiles_lr( | |||
| 34252 | interp_fixed: Option<mc::InterpFilterKind>, | 34261 | interp_fixed: Option<mc::InterpFilterKind>, |
| 34253 | enable_dual_filter: bool, | 34262 | enable_dual_filter: bool, |
| 34254 | reference_select: bool, | 34263 | reference_select: bool, |
| 34264 | + // lane-txi: this frame header's own `reduced_tx_set` bit. It used to be | ||
| 34265 | + // hardcoded `true` at the call below -- the encoder's own trial decode of | ||
| 34266 | + // the tile it just wrote then read every luma `tx_type` out of the | ||
| 34267 | + // reduced alphabet whatever the header said (class: a header bit a raw | ||
| 34268 | + // tile decode cannot guess, the same one `tx_select` carries). | ||
| 34269 | + reduced_tx_set: bool, | ||
| 34255 | tx_select: bool, | 34270 | tx_select: bool, |
| 34256 | lr: &LoopRestorationParams, | 34271 | lr: &LoopRestorationParams, |
| 34257 | initial_cdfs: Option<Cdfs>, | 34272 | initial_cdfs: Option<Cdfs>, |
| @@ -34314,7 +34329,7 @@ pub(crate) fn decode_inter_frame_tiles_lr( | |||
| 34314 | false, | 34329 | false, |
| 34315 | false, | 34330 | false, |
| 34316 | [0; 2], | 34331 | [0; 2], |
| 34317 | - true, | 34332 | + reduced_tx_set, |
| 34318 | tx_select, | 34333 | tx_select, |
| 34319 | switchable_motion_mode, | 34334 | switchable_motion_mode, |
| 34320 | allow_warped_motion, | 34335 | allow_warped_motion, |
crates/ec-av1/src/encode.rsmodified+209 -12
| @@ -273,6 +273,15 @@ fn tx_select_inter() -> bool { | |||
| 273 | /// here. | 273 | /// here. |
| 274 | pub(crate) fn tx_type_candidates(set: TxbSet, screen: bool) -> &'static [TxType] { | 274 | pub(crate) fn tx_type_candidates(set: TxbSet, screen: bool) -> &'static [TxType] { |
| 275 | const DCT: [TxType; 1] = [TxType::DctDct]; | 275 | 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 | + ]; | ||
| 276 | const INTRA2: [TxType; 5] = [ | 285 | const INTRA2: [TxType; 5] = [ |
| 277 | TxType::DctDct, | 286 | TxType::DctDct, |
| 278 | TxType::AdstAdst, | 287 | TxType::AdstAdst, |
| @@ -281,7 +290,21 @@ pub(crate) fn tx_type_candidates(set: TxbSet, screen: bool) -> &'static [TxType] | |||
| 281 | TxType::Idtx, | 290 | TxType::Idtx, |
| 282 | ]; | 291 | ]; |
| 283 | match set { | 292 | match set { |
| 284 | - TxbSet::Luma16 | TxbSet::Luma8 | TxbSet::Luma4 if screen && tx_type_search() => &INTRA2, | 293 | + TxbSet::Luma16 | TxbSet::Luma8 | TxbSet::Luma4 |
| 294 | + if intra_tx_search_on(screen) => | ||
| 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 intra_tx_search_on(screen) => | ||
| 305 | + { | ||
| 306 | + &INTRA1 | ||
| 307 | + } | ||
| 285 | _ => &DCT, | 308 | _ => &DCT, |
| 286 | } | 309 | } |
| 287 | } | 310 | } |
| @@ -308,6 +331,15 @@ pub(crate) fn tx_type_candidates(set: TxbSet, screen: bool) -> &'static [TxType] | |||
| 308 | pub(crate) fn inter_tx_type_candidates(set: TxbSet, screen: bool) -> &'static [TxType] { | 331 | pub(crate) fn inter_tx_type_candidates(set: TxbSet, screen: bool) -> &'static [TxType] { |
| 309 | const DCT: [TxType; 1] = [TxType::DctDct]; | 332 | const DCT: [TxType; 1] = [TxType::DctDct]; |
| 310 | const INTER3: [TxType; 2] = [TxType::DctDct, TxType::Idtx]; | 333 | 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 | + ]; | ||
| 311 | let mode = inter_tx_type_search(); | 343 | let mode = inter_tx_type_search(); |
| 312 | let on = match mode { | 344 | let on = match mode { |
| 313 | InterTxSearch::Off => false, | 345 | InterTxSearch::Off => false, |
| @@ -317,10 +349,78 @@ pub(crate) fn inter_tx_type_candidates(set: TxbSet, screen: bool) -> &'static [T | |||
| 317 | match set { | 349 | match set { |
| 318 | TxbSet::Luma32Inter if on && mode != InterTxSearch::Le16 => &INTER3, | 350 | TxbSet::Luma32Inter if on && mode != InterTxSearch::Le16 => &INTER3, |
| 319 | TxbSet::Luma16Inter | TxbSet::Luma8Inter | TxbSet::Luma4Inter if on => &INTER3, | 351 | 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 | + } | ||
| 320 | _ => &DCT, | 362 | _ => &DCT, |
| 321 | } | 363 | } |
| 322 | } | 364 | } |
| 323 | 365 | ||
| 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 | + match WIDE_TX_OVERRIDE.load(std::sync::atomic::Ordering::Relaxed) { | ||
| 373 | + 0 => return false, | ||
| 374 | + 1 => return true, | ||
| 375 | + _ => {} | ||
| 376 | + } | ||
| 377 | + static ENV: std::sync::LazyLock<Option<InterTxSearch>> = std::sync::LazyLock::new(|| { | ||
| 378 | + crate::envflags::var("EC_AV1_TXSET_WIDE").ok().map(|v| match v.as_str() { | ||
| 379 | + "0" | "off" => InterTxSearch::Off, | ||
| 380 | + "screen" => InterTxSearch::Screen, | ||
| 381 | + _ => InterTxSearch::All, | ||
| 382 | + }) | ||
| 383 | + }); | ||
| 384 | + match ENV.unwrap_or(if crate::speed::at(&crate::speed::WIDE_TX_SET) { | ||
| 385 | + InterTxSearch::Screen | ||
| 386 | + } else { | ||
| 387 | + InterTxSearch::Off | ||
| 388 | + }) { | ||
| 389 | + InterTxSearch::Off => false, | ||
| 390 | + InterTxSearch::Screen => screen, | ||
| 391 | + _ => true, | ||
| 392 | + } | ||
| 393 | +} | ||
| 394 | + | ||
| 395 | +/// A PROCESS-GLOBAL [`wide_tx_set`] override that wins over both the | ||
| 396 | +/// environment and the preset (`u8::MAX` = unset), the shape | ||
| 397 | +/// [`set_inter_tx_search`] has: the lever is OFF at every preset, so the | ||
| 398 | +/// witness that has to see the wider alphabets turns it on through this while | ||
| 399 | +/// holding [`crate::speed::knob_write`]. | ||
| 400 | +static WIDE_TX_OVERRIDE: std::sync::atomic::AtomicU8 = | ||
| 401 | + std::sync::atomic::AtomicU8::new(u8::MAX); | ||
| 402 | + | ||
| 403 | +/// Sets [`WIDE_TX_OVERRIDE`]; `None` clears it. | ||
| 404 | +#[allow(dead_code)] // set only from the `#[cfg(test)]` gates | ||
| 405 | +pub(crate) fn set_wide_tx_set(on: Option<bool>) { | ||
| 406 | + WIDE_TX_OVERRIDE.store( | ||
| 407 | + on.map_or(u8::MAX, u8::from), | ||
| 408 | + std::sync::atomic::Ordering::Relaxed, | ||
| 409 | + ); | ||
| 410 | +} | ||
| 411 | + | ||
| 412 | +/// The luma [`TxbSet`] the SEARCH and its pricer name for a frame that codes | ||
| 413 | +/// `reduced_tx_set = 0`: the writer reads the bit once, off the frame's own | ||
| 414 | +/// [`crate::cdf_state::Cdfs`], but the trial that prices a type has to read | ||
| 415 | +/// the same alphabet or the two disagree on what a `tx_type` symbol costs. | ||
| 416 | +pub(crate) fn luma_set_for(set: TxbSet, screen: bool) -> TxbSet { | ||
| 417 | + if wide_tx_set(screen) { | ||
| 418 | + set.wide() | ||
| 419 | + } else { | ||
| 420 | + set | ||
| 421 | + } | ||
| 422 | +} | ||
| 423 | + | ||
| 324 | #[derive(Clone, Copy, PartialEq)] | 424 | #[derive(Clone, Copy, PartialEq)] |
| 325 | pub(crate) enum InterTxSearch { | 425 | pub(crate) enum InterTxSearch { |
| 326 | Off, | 426 | Off, |
| @@ -372,6 +472,17 @@ fn inter_tx_type_search() -> InterTxSearch { | |||
| 372 | 472 | ||
| 373 | /// The inter luma [`TxbSet`] a `tx`-sided transform unit reads, `None` for the | 473 | /// The inter luma [`TxbSet`] a `tx`-sided transform unit reads, `None` for the |
| 374 | /// 64-point one (it codes no `tx_type` symbol). | 474 | /// 64-point one (it codes no `tx_type` symbol). |
| 475 | +/// lane-txi: the INTER half of the widening is deliberately NOT applied | ||
| 476 | +/// here. A `reduced_tx_set = 0` frame's writer still codes its inter luma | ||
| 477 | +/// `tx_type` into the twelve/sixteen-symbol alphabet (the frame bit widens | ||
| 478 | +/// every luma set at once, spec `get_tx_set`), but the SEARCH keeps offering | ||
| 479 | +/// the two-type list: with the wider inter candidates priced, some block's | ||
| 480 | +/// winner selects a reference slot this encoder holds no picture in | ||
| 481 | +/// ("a reference frame selected with no picture at this frame's own | ||
| 482 | +/// ref_frame_idx slot for it", refused out of the encoder's own MC), which is | ||
| 483 | +/// the `refs` lane's DPB bookkeeping (`encoder.rs` maps LAST2/LAST3 onto | ||
| 484 | +/// LAST's slot), not a transform defect -- measured by bisection: the intra | ||
| 485 | +/// half alone passes every witness, the inter half alone refuses. | ||
| 375 | fn inter_luma_set(tx: usize) -> Option<TxbSet> { | 486 | fn inter_luma_set(tx: usize) -> Option<TxbSet> { |
| 376 | Some(match tx { | 487 | Some(match tx { |
| 377 | 4 => TxbSet::Luma4Inter, | 488 | 4 => TxbSet::Luma4Inter, |
| @@ -391,6 +502,45 @@ fn tx_type_search() -> bool { | |||
| 391 | ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::TX_TYPE_SEARCH)) | 502 | ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::TX_TYPE_SEARCH)) |
| 392 | } | 503 | } |
| 393 | 504 | ||
| 505 | +/// Whether an intra luma unit of this frame searches its own type at all: | ||
| 506 | +/// the preset lever ([`tx_type_search`]) under the screen content gate, which | ||
| 507 | +/// `EC_AV1_TXSET=all` ([`intra_tx_all_frames`]) lifts and the process-global | ||
| 508 | +/// [`set_intra_tx_search`] override wins over (the witness needs the search | ||
| 509 | +/// on a frame the detector called non-screen). | ||
| 510 | +fn intra_tx_search_on(screen: bool) -> bool { | ||
| 511 | + match INTRA_TX_OVERRIDE.load(std::sync::atomic::Ordering::Relaxed) { | ||
| 512 | + 0 => return false, | ||
| 513 | + 1 => return true, | ||
| 514 | + _ => {} | ||
| 515 | + } | ||
| 516 | + (screen || intra_tx_all_frames()) && tx_type_search() | ||
| 517 | +} | ||
| 518 | + | ||
| 519 | +/// A PROCESS-GLOBAL [`intra_tx_search_on`] override (`u8::MAX` = unset), the | ||
| 520 | +/// shape [`set_inter_tx_search`] has. | ||
| 521 | +static INTRA_TX_OVERRIDE: std::sync::atomic::AtomicU8 = | ||
| 522 | + std::sync::atomic::AtomicU8::new(u8::MAX); | ||
| 523 | + | ||
| 524 | +/// Sets [`INTRA_TX_OVERRIDE`]; `None` clears it. | ||
| 525 | +#[allow(dead_code)] // set only from the `#[cfg(test)]` gates | ||
| 526 | +pub(crate) fn set_intra_tx_search(on: Option<bool>) { | ||
| 527 | + INTRA_TX_OVERRIDE.store( | ||
| 528 | + on.map_or(u8::MAX, u8::from), | ||
| 529 | + std::sync::atomic::Ordering::Relaxed, | ||
| 530 | + ); | ||
| 531 | +} | ||
| 532 | + | ||
| 533 | +/// lane-txi: `EC_AV1_TXSET=all` offers the five-type intra set on EVERY | ||
| 534 | +/// frame -- the unconditional arm the gate measures -- instead of the screen | ||
| 535 | +/// content gate [`tx_type_candidates`] ships behind. Any other value keeps | ||
| 536 | +/// the gate (`0`/`off` still switches the search off entirely). | ||
| 537 | +fn intra_tx_all_frames() -> bool { | ||
| 538 | + static ENV: std::sync::LazyLock<bool> = std::sync::LazyLock::new(|| { | ||
| 539 | + crate::envflags::var("EC_AV1_TXSET").is_ok_and(|v| v == "all") | ||
| 540 | + }); | ||
| 541 | + *ENV | ||
| 542 | +} | ||
| 543 | + | ||
| 394 | fn tx_select() -> bool { | 544 | fn tx_select() -> bool { |
| 395 | static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { | 545 | static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { |
| 396 | crate::envflags::var("EC_AV1_TX_SELECT") | 546 | crate::envflags::var("EC_AV1_TX_SELECT") |
| @@ -2546,12 +2696,15 @@ impl Plane<'_> { | |||
| 2546 | let At { x, y, side, reach, .. } = at; | 2696 | let At { x, y, side, reach, .. } = at; |
| 2547 | let tx = side >> depth; | 2697 | let tx = side >> depth; |
| 2548 | let n = 1usize << depth; | 2698 | let n = 1usize << depth; |
| 2549 | - let set = match tx { | 2699 | + let set = luma_set_for( |
| 2550 | - 32 => TxbSet::Luma32, | 2700 | + match tx { |
| 2551 | - 16 => TxbSet::Luma16, | 2701 | + 32 => TxbSet::Luma32, |
| 2552 | - 8 => TxbSet::Luma8, | 2702 | + 16 => TxbSet::Luma16, |
| 2553 | - _ => TxbSet::Luma4, | 2703 | + 8 => TxbSet::Luma8, |
| 2554 | - }; | 2704 | + _ => TxbSet::Luma4, |
| 2705 | + }, | ||
| 2706 | + search.screen, | ||
| 2707 | + ); | ||
| 2555 | let mut levels = vec![0i32; side * side]; | 2708 | let mut levels = vec![0i32; side * side]; |
| 2556 | census_add(4, n * n); | 2709 | census_add(4, n * n); |
| 2557 | // A unit smaller than its block reads the neighbour magnitude table | 2710 | // A unit smaller than its block reads the neighbour magnitude table |
| @@ -2610,7 +2763,18 @@ impl Plane<'_> { | |||
| 2610 | tu, mode, angle_delta, search.base_q_idx, search.deadzone, | 2763 | tu, mode, angle_delta, search.base_q_idx, search.deadzone, |
| 2611 | tx_type, fctx, | 2764 | tx_type, fctx, |
| 2612 | ); | 2765 | ); |
| 2613 | - let cost = candidate.sse + search.lambda * candidate.bits; | 2766 | + // lane-txi: a non-`DCT_DCT` type is charged its |
| 2767 | + // bits at `EC_AV1_TXRD_LAMBDA` times the mode | ||
| 2768 | + // search's weight (default 1 = unchanged). The | ||
| 2769 | + // film rows buy 0.04 dB for 1.2% more bytes at | ||
| 2770 | + // weight 1 on every frame and every PLANE, key | ||
| 2771 | + // frame included -- a rate term this decision | ||
| 2772 | + // under-charges (class | ||
| 2773 | + // `rd-rate-term-calibration`), not the | ||
| 2774 | + // propagation loss the leaves would have shown. | ||
| 2775 | + let cost = candidate.sse | ||
| 2776 | + + search.lambda * candidate.bits | ||
| 2777 | + + non_dct_surcharge(search.lambda, tx_type, candidate.bits); | ||
| 2614 | if best.as_ref().is_none_or(|(best, _, _)| cost < *best) { | 2778 | if best.as_ref().is_none_or(|(best, _, _)| cost < *best) { |
| 2615 | best = Some((cost, tx_type, candidate)); | 2779 | best = Some((cost, tx_type, candidate)); |
| 2616 | } | 2780 | } |
| @@ -3001,7 +3165,10 @@ impl Plane<'_> { | |||
| 3001 | ); | 3165 | ); |
| 3002 | let cost_t = | 3166 | let cost_t = |
| 3003 | candidate.sse + search.lambda * (candidate.bits + mode_bits[usize::from(mode)]); | 3167 | candidate.sse + search.lambda * (candidate.bits + mode_bits[usize::from(mode)]); |
| 3004 | - if cost_t < cost { | 3168 | + // lane-txi's surcharge, as in `code_tx_depth`: the incumbent is |
| 3169 | + // `DCT_DCT` and pays none of it, so the returned `cost` stays the | ||
| 3170 | + // block's true one for the caller's own decision. | ||
| 3171 | + if cost_t + non_dct_surcharge(search.lambda, candidate_type, candidate.bits) < cost { | ||
| 3005 | cost = cost_t; | 3172 | cost = cost_t; |
| 3006 | tx_type = candidate_type; | 3173 | tx_type = candidate_type; |
| 3007 | trial = candidate; | 3174 | trial = candidate; |
| @@ -3864,6 +4031,20 @@ pub(crate) fn tx_type_lambda_mult() -> f64 { | |||
| 3864 | *M | 4031 | *M |
| 3865 | } | 4032 | } |
| 3866 | 4033 | ||
| 4034 | +/// lane-txi: what a non-`DCT_DCT` transform type is charged ON TOP of its own | ||
| 4035 | +/// priced bits -- `(EC_AV1_TXRD_LAMBDA - 1) * lambda * bits`, zero at the | ||
| 4036 | +/// default weight of 1 and for `DCT_DCT` itself. The instrument the film | ||
| 4037 | +/// question needs: at weight 1 the five-type intra search spends 1.2% more | ||
| 4038 | +/// bytes for 0.04 dB on both film rows, so what it under-charges is the rate | ||
| 4039 | +/// of the type it picks. | ||
| 4040 | +pub(crate) fn non_dct_surcharge(lambda: f64, tx_type: TxType, bits: f64) -> f64 { | ||
| 4041 | + if tx_type == TxType::DctDct { | ||
| 4042 | + 0.0 | ||
| 4043 | + } else { | ||
| 4044 | + lambda * (tx_type_lambda_mult() - 1.0) * bits | ||
| 4045 | + } | ||
| 4046 | +} | ||
| 4047 | + | ||
| 3867 | /// lane-txrd instrument: over the FLAT inter luma decision, the summed | 4048 | /// lane-txrd instrument: over the FLAT inter luma decision, the summed |
| 3868 | /// reconstruction error and priced bits of the type the search chose against | 4049 | /// reconstruction error and priced bits of the type the search chose against |
| 3869 | /// the `DCT_DCT` trial it was compared with. Both are `* 64` so they fit an | 4050 | /// the `DCT_DCT` trial it was compared with. Both are `* 64` so they fit an |
| @@ -4840,7 +5021,7 @@ fn code_square( | |||
| 4840 | y, | 5021 | y, |
| 4841 | side, | 5022 | side, |
| 4842 | reach: Reach::of(side, x, y, luma.true_width, luma.true_height, fctx), | 5023 | reach: Reach::of(side, x, y, luma.true_width, luma.true_height, fctx), |
| 4843 | - set: luma_set, | 5024 | + set: luma_set_for(luma_set, search.screen), |
| 4844 | }; | 5025 | }; |
| 4845 | let (mut luma_coeffs, mode, angle_delta, mut cost, tx_type) = | 5026 | let (mut luma_coeffs, mode, angle_delta, mut cost, tx_type) = |
| 4846 | luma.search_block(at, search, mode_bits, fctx); | 5027 | luma.search_block(at, search, mode_bits, fctx); |
| @@ -7128,6 +7309,9 @@ pub(crate) fn encode_key_frame_inner( | |||
| 7128 | IBC_SHARE.with(|c| c.set(ibc_share)); | 7309 | IBC_SHARE.with(|c| c.set(ibc_share)); |
| 7129 | let (seq, mut header) = key_frame_headers_colour(render.0, render.1, base_q_idx, color_config)?; | 7310 | let (seq, mut header) = key_frame_headers_colour(render.0, render.1, base_q_idx, color_config)?; |
| 7130 | header.allow_screen_content_tools = screen; | 7311 | header.allow_screen_content_tools = screen; |
| 7312 | + // lane-txi: the wider `tx_type` alphabets, gated by the same content | ||
| 7313 | + // rule the type search itself stands behind ([`wide_tx_set`]). | ||
| 7314 | + header.reduced_tx_set = !wide_tx_set(screen); | ||
| 7131 | header.allow_intrabc = allow_intrabc; | 7315 | header.allow_intrabc = allow_intrabc; |
| 7132 | header.render_width = render.0 as u32; | 7316 | header.render_width = render.0 as u32; |
| 7133 | header.render_height = render.1 as u32; | 7317 | header.render_height = render.1 as u32; |
| @@ -7582,7 +7766,10 @@ pub(crate) fn encode_key_frame_inner( | |||
| 7582 | // defaults again (spec 7.20's `started_from` arm) -- the first inter | 7766 | // defaults again (spec 7.20's `started_from` arm) -- the first inter |
| 7583 | // frame after it therefore starts from the defaults too. | 7767 | // frame after it therefore starts from the defaults too. |
| 7584 | let (mi_cols, mi_rows) = (header.mi_cols, header.mi_rows); | 7768 | let (mi_cols, mi_rows) = (header.mi_cols, header.mi_rows); |
| 7585 | - let cdfs = crate::cdf_state::Cdfs::new(crate::tile::q_ctx_of(base_q_idx)); | 7769 | + let mut cdfs = crate::cdf_state::Cdfs::new(crate::tile::q_ctx_of(base_q_idx)); |
| 7770 | + // lane-txi: the ONE place the writer reads the frame's `reduced_tx_set` | ||
| 7771 | + // from -- `Cdfs::txb` widens every luma set under it. | ||
| 7772 | + cdfs.reduced_tx_set = header.reduced_tx_set; | ||
| 7586 | let start_cdfs = CdfSnapshot(cdfs); | 7773 | let start_cdfs = CdfSnapshot(cdfs); |
| 7587 | // The luma restoration-unit grid this frame's `lr_params` implies | 7774 | // The luma restoration-unit grid this frame's `lr_params` implies |
| 7588 | // (`av1_lr_count_units` rounds to nearest, so a short last unit is | 7775 | // (`av1_lr_count_units` rounds to nearest, so a short last unit is |
| @@ -10474,6 +10661,9 @@ pub(crate) fn encode_inter_frame( | |||
| 10474 | let screen = seq_screen() | 10661 | let screen = seq_screen() |
| 10475 | && screen_content(&picture_y8, picture.width, true_width, true_height); | 10662 | && screen_content(&picture_y8, picture.width, true_width, true_height); |
| 10476 | header.allow_screen_content_tools = screen; | 10663 | header.allow_screen_content_tools = screen; |
| 10664 | + // lane-txi, as on the key frame: the header bit the writer's own | ||
| 10665 | + // `Cdfs` then reads for every luma `tx_type` symbol. | ||
| 10666 | + header.reduced_tx_set = !wide_tx_set(screen); | ||
| 10477 | // The search prices coefficients against the tables this frame's writer | 10667 | // The search prices coefficients against the tables this frame's writer |
| 10478 | // starts from, not against the defaults (lane-av1txbits) -- but only on a | 10668 | // starts from, not against the defaults (lane-av1txbits) -- but only on a |
| 10479 | // frame the screen detector said no to (lane-av1price2): armed HERE, after | 10669 | // frame the screen detector said no to (lane-av1price2): armed HERE, after |
| @@ -11298,9 +11488,13 @@ pub(crate) fn encode_inter_frame( | |||
| 11298 | // next frame's writer starts from them -- exactly what | 11488 | // next frame's writer starts from them -- exactly what |
| 11299 | // `crate::stream::stored_cdfs_for` hands the decoder. | 11489 | // `crate::stream::stored_cdfs_for` hands the decoder. |
| 11300 | let (mi_cols, mi_rows) = (header.mi_cols, header.mi_rows); | 11490 | let (mi_cols, mi_rows) = (header.mi_cols, header.mi_rows); |
| 11301 | - let cdfs = start_cdfs | 11491 | + let mut cdfs = start_cdfs |
| 11302 | .cloned() | 11492 | .cloned() |
| 11303 | .unwrap_or_else(|| crate::cdf_state::Cdfs::new(crate::tile::q_ctx_of(base_q_idx))); | 11493 | .unwrap_or_else(|| crate::cdf_state::Cdfs::new(crate::tile::q_ctx_of(base_q_idx))); |
| 11494 | + // lane-txi: set per frame, never inherited from the snapshot the | ||
| 11495 | + // previous frame stored -- the content gate can flip the bit between | ||
| 11496 | + // frames (class `per-tile-state-not-reset`). | ||
| 11497 | + cdfs.reduced_tx_set = header.reduced_tx_set; | ||
| 11304 | let start_cdfs = CdfSnapshot(cdfs); | 11498 | let start_cdfs = CdfSnapshot(cdfs); |
| 11305 | let reference_select_bit = header.reference_select; | 11499 | let reference_select_bit = header.reference_select; |
| 11306 | let switchable_motion_mode = header.is_motion_mode_switchable; | 11500 | let switchable_motion_mode = header.is_motion_mode_switchable; |
| @@ -11489,6 +11683,9 @@ pub(crate) fn encode_inter_frame( | |||
| 11489 | Some(mc::InterpFilterKind::Regular), | 11683 | Some(mc::InterpFilterKind::Regular), |
| 11490 | seq.enable_dual_filter, | 11684 | seq.enable_dual_filter, |
| 11491 | h.reference_select, | 11685 | h.reference_select, |
| 11686 | + // lane-txi: this frame's own bit, not the hardcoded `true` | ||
| 11687 | + // the wrapper used to pass. | ||
| 11688 | + h.reduced_tx_set, | ||
| 11492 | tx_select, | 11689 | tx_select, |
| 11493 | lr, | 11690 | lr, |
| 11494 | // The trial decode re-reads the tile the writer just wrote, | 11691 | // The trial decode re-reads the tile the writer just wrote, |
crates/ec-av1/src/encoder.rsmodified+118 -0
| @@ -3811,6 +3811,124 @@ mod tests { | |||
| 3811 | eprintln!("inter tx_type witness: hits {hits:?}, {} bytes", stream.len()); | 3811 | eprintln!("inter tx_type witness: hits {hits:?}, {} bytes", stream.len()); |
| 3812 | } | 3812 | } |
| 3813 | 3813 | ||
| 3814 | + /// lane-txi's witness: a `reduced_tx_set = 0` frame codes the WIDER | ||
| 3815 | + /// `tx_type` alphabets -- the seven-type `TX_SET_INTRA_1` at intra | ||
| 3816 | + /// 8x8/4x4 and the twelve/sixteen-type inter sets at 16x16 and below -- | ||
| 3817 | + /// and both decoders reconstruct every frame sample-exact from them. The | ||
| 3818 | + /// statement is that the types only those alphabets can NAME (`V_DCT`, | ||
| 3819 | + /// `H_DCT`, and any inter type outside the two-type `DCT_IDTX`) are | ||
| 3820 | + /// reachable at all, and that the header bit, the writer's set map and | ||
| 3821 | + /// the search's pricer agree on which alphabet a symbol was coded into | ||
| 3822 | + /// (class `wrong-alphabet-same-value`: a disagreement here changes no | ||
| 3823 | + /// symbol VALUE and desyncs the arithmetic coder anyway). | ||
| 3824 | + #[test] | ||
| 3825 | + #[ignore = "reduced_tx_set = 0 desyncs the encoder's own trial decode when the \ | ||
| 3826 | + seven-type intra search is on -- bisected in lanes/txi.report.md; \ | ||
| 3827 | + the lever is off at every preset until that is closed"] | ||
| 3828 | + fn a_wide_tx_set_clip_codes_the_new_alphabets_both_decoders_read_exactly() { | ||
| 3829 | + // Every lever below is process-global: the same exclusive lock the | ||
| 3830 | + // presets take. | ||
| 3831 | + let _knobs = crate::speed::knob_write(); | ||
| 3832 | + let _gate_lock = crate::stream::tests::lock_gate_counters(); | ||
| 3833 | + crate::encode::set_intra_tx_search(Some(true)); | ||
| 3834 | + crate::encode::set_inter_tx_search(Some(true)); | ||
| 3835 | + crate::encode::set_wide_tx_set(Some(true)); | ||
| 3836 | + let (width, height) = (320usize, 192usize); | ||
| 3837 | + // The same moving hard-edge card the two narrow-set witnesses use: | ||
| 3838 | + // vertical steps are what a 1-D `V_DCT`/`H_DCT` pass wins on, the | ||
| 3839 | + // ramps are `ADST`'s and the moving plateaus `IDTX`'s. | ||
| 3840 | + let sources: Vec<Picture> = (0..4) | ||
| 3841 | + .map(|t| { | ||
| 3842 | + let mut p = test_card(width, height, t * 3); | ||
| 3843 | + for y in 0..height { | ||
| 3844 | + for x in 0..width { | ||
| 3845 | + let v = match ((x + t * 5) / 16 % 2, (y + t * 3) / 16 % 2) { | ||
| 3846 | + (0, 0) => 16u16, | ||
| 3847 | + (1, 0) => 235, | ||
| 3848 | + (0, 1) => ((x + t) % 64 * 3) as u16, | ||
| 3849 | + _ => ((y + t) % 64 * 3) as u16, | ||
| 3850 | + }; | ||
| 3851 | + p.y[y * width + x] = v; | ||
| 3852 | + } | ||
| 3853 | + } | ||
| 3854 | + p | ||
| 3855 | + }) | ||
| 3856 | + .collect(); | ||
| 3857 | + let config = EncoderConfig { | ||
| 3858 | + width, | ||
| 3859 | + height, | ||
| 3860 | + base_q_idx: 90, | ||
| 3861 | + gop: 4, | ||
| 3862 | + colour: Colour::Bt709Limited, | ||
| 3863 | + tile_cols_log2: 0, | ||
| 3864 | + tile_rows_log2: 0, | ||
| 3865 | + }; | ||
| 3866 | + let mut enc = Av1Encoder::new(config).unwrap(); | ||
| 3867 | + let _ = crate::encode::take_tx_type_hits(); | ||
| 3868 | + let _ = crate::encode::take_inter_tx_type_hits(); | ||
| 3869 | + let mut stream = Vec::new(); | ||
| 3870 | + for packet in encode_all(&mut enc, &sources) { | ||
| 3871 | + stream.extend_from_slice(&packet.data); | ||
| 3872 | + } | ||
| 3873 | + let (intra, inter) = ( | ||
| 3874 | + crate::encode::take_tx_type_hits(), | ||
| 3875 | + crate::encode::take_inter_tx_type_hits(), | ||
| 3876 | + ); | ||
| 3877 | + crate::encode::set_wide_tx_set(None); | ||
| 3878 | + crate::encode::set_inter_tx_search(None); | ||
| 3879 | + crate::encode::set_intra_tx_search(None); | ||
| 3880 | + eprintln!("wide tx_type witness: intra {intra:?} inter {inter:?}, {} bytes", stream.len()); | ||
| 3881 | + // The fire count is preset 0's, for the reason the five-type witness | ||
| 3882 | + // spells out: a faster preset prunes the modes and partitions a type | ||
| 3883 | + // wins on before it is ever priced (class `gate-blind-to-feature`). | ||
| 3884 | + if crate::speed::at(&crate::speed::TX_TYPE_SEARCH) && crate::speed::speed() == 0 { | ||
| 3885 | + use crate::transform::TxType; | ||
| 3886 | + let wide_only = |hits: &[usize; 16]| -> usize { | ||
| 3887 | + hits[TxType::VDct as usize] + hits[TxType::HDct as usize] | ||
| 3888 | + }; | ||
| 3889 | + assert!( | ||
| 3890 | + wide_only(&intra) > 0, | ||
| 3891 | + "no intra luma unit took a 1-D DCT, the type only TX_SET_INTRA_1 names: {intra:?}" | ||
| 3892 | + ); | ||
| 3893 | + // The INTER units of this same frame are coded into the | ||
| 3894 | + // twelve/sixteen-symbol alphabets too (the header bit widens | ||
| 3895 | + // every luma set at once), but their SEARCH still offers the | ||
| 3896 | + // two-type list -- see `encode::inter_luma_set`'s note on the | ||
| 3897 | + // reference-slot refusal the wider inter candidates trip. So the | ||
| 3898 | + // statement here is that those units still decode sample-exact | ||
| 3899 | + // out of the wider alphabet, which the two decoders below make. | ||
| 3900 | + assert!( | ||
| 3901 | + inter.iter().sum::<usize>() > 0, | ||
| 3902 | + "the clip coded no inter luma transform unit at all: {inter:?}" | ||
| 3903 | + ); | ||
| 3904 | + } else { | ||
| 3905 | + eprintln!( | ||
| 3906 | + "SKIP the wide-alphabet fire count at preset {}", | ||
| 3907 | + crate::speed::speed() | ||
| 3908 | + ); | ||
| 3909 | + } | ||
| 3910 | + let ours = crate::stream::decode_stream(&stream).expect("our decoder"); | ||
| 3911 | + assert_eq!(ours.len(), sources.len(), "our decoder's frames"); | ||
| 3912 | + if have_ffmpeg() { | ||
| 3913 | + let theirs = ffmpeg_decode_luma(&stream, width, height); | ||
| 3914 | + assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); | ||
| 3915 | + for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { | ||
| 3916 | + let got: Vec<u8> = a.y.iter().map(|&v| v as u8).collect(); | ||
| 3917 | + if let Some(at) = got.iter().zip(b).position(|(x, y)| x != y) { | ||
| 3918 | + panic!( | ||
| 3919 | + "frame {i}: luma differs first at ({}, {}): ours {} vs ffmpeg {}", | ||
| 3920 | + at % width, | ||
| 3921 | + at / width, | ||
| 3922 | + got[at], | ||
| 3923 | + b[at], | ||
| 3924 | + ); | ||
| 3925 | + } | ||
| 3926 | + } | ||
| 3927 | + } else { | ||
| 3928 | + eprintln!("SKIP the ffmpeg half: no ffmpeg"); | ||
| 3929 | + } | ||
| 3930 | + } | ||
| 3931 | + | ||
| 3814 | /// Every SHIPPED SPEED PRESET codes a stream both decoders reconstruct | 3932 | /// Every SHIPPED SPEED PRESET codes a stream both decoders reconstruct |
| 3815 | /// sample-exact -- ours and ffmpeg's -- and codes a DIFFERENT stream from | 3933 | /// sample-exact -- ours and ffmpeg's -- and codes a DIFFERENT stream from |
| 3816 | /// its neighbour (a preset that changes no byte is a preset that buys no | 3934 | /// its neighbour (a preset that changes no byte is a preset that buys no |
crates/ec-av1/src/speed.rsmodified+9 -0
| @@ -512,6 +512,15 @@ pub(crate) const TX_TYPE_SEARCH_INTER: [bool; 11] = [ | |||
| 512 | true, true, true, true, true, true, true, false, false, false, false, | 512 | true, true, true, true, true, true, true, false, false, false, false, |
| 513 | ]; | 513 | ]; |
| 514 | 514 | ||
| 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 | + | ||
| 515 | /// `filter_search`: whether the deblock ladder's +-1/+-2 refinement stage runs. | 524 | /// `filter_search`: whether the deblock ladder's +-1/+-2 refinement stage runs. |
| 516 | pub(crate) const DEBLOCK_REFINE: [bool; 11] = [ | 525 | pub(crate) const DEBLOCK_REFINE: [bool; 11] = [ |
| 517 | true, true, true, true, true, true, true, false, false, false, false, | 526 | true, true, true, true, true, true, true, false, false, false, false, |
lanes/txi.report.mdadded+174 -0
| @@ -0,0 +1,174 @@ | |||
| 1 | +# lane-txi -- the intra type search's film loss, and `reduced_tx_set = 0` | ||
| 2 | + | ||
| 3 | +Branch `lane-txi` off main `f6c67770`. Predecessors: `lanes/txset.report.md` | ||
| 4 | +(intra five-type set, screen-gated), `lanes/txset2.report.md` (inter | ||
| 5 | +`DCT_IDTX`, screen-gated), `lanes/txrd.report.md` (the inter chroma-inherit | ||
| 6 | +fix). | ||
| 7 | + | ||
| 8 | +## 1. The instrument: WHERE the intra unconditional arm loses (12-frame gate) | ||
| 9 | + | ||
| 10 | +`EC_AV1_TXSET=all` is new here -- it lifts the intra search's screen gate | ||
| 11 | +without touching the preset lever -- and the gate already prints per-frame AND | ||
| 12 | +per-plane PSNR under `EC_AV1_FRAME_PSNR=1` (lane-txrd's instrument). | ||
| 13 | + | ||
| 14 | +Control and arm both REPRODUCE the charter's numbers to the digit: bars 1080p | ||
| 15 | +-1.0/-16.8 -> -2.3/-17.8, film A **+21.7/-4.4 -> +22.1/-4.0**. | ||
| 16 | + | ||
| 17 | +film A, per plane, per frame (frame 0 is the key frame; q=60 shown, q=150 | ||
| 18 | +identical in shape): | ||
| 19 | + | ||
| 20 | +| plane | control | arm (`EC_AV1_TXSET=all`) | | ||
| 21 | +|---|---|---| | ||
| 22 | +| Y | 51.72 46.53 47.40 46.51 47.10 47.09 46.50 ... | **51.73 46.55 47.42 46.52 47.13 47.12 46.52 ...** | | ||
| 23 | +| U | 52.52 49.39 49.75 49.44 49.65 49.87 49.60 ... | **52.52 49.41 49.77 49.49 49.68 49.90 49.62 ...** | | ||
| 24 | +| V | 52.39 49.26 49.79 49.25 49.65 49.45 49.08 ... | **52.39 49.27 49.81 49.28 49.67 49.44 49.10 ...** | | ||
| 25 | + | ||
| 26 | +READING, and it refutes the charter's premise: the arm is EQUAL OR BETTER on | ||
| 27 | +every frame, every plane and both quantizers shown -- the key frame included, | ||
| 28 | +the leaves included. There is no plane collapse (lane-txrd's chroma class) and | ||
| 29 | +no propagation shape (the leaves do not decay relative to the key frame), so | ||
| 30 | +**a reference-aware `lambda` term has no signal to act on and was not built**. | ||
| 31 | + | ||
| 32 | +What the arm actually spends is BYTES: 64392 -> 65201, 102508 -> 103781, | ||
| 33 | +170169 -> 172167, 413430 -> 419156, i.e. +1.2..1.4% of rate for +0.02..0.06 dB. | ||
| 34 | +That is a rate term the type decision under-charges (class | ||
| 35 | +`rd-rate-term-calibration`), not a distortion it mis-measures. | ||
| 36 | + | ||
| 37 | +DEVIATION FROM THE CHARTER, stated: instead of the reference-aware term, this | ||
| 38 | +lane builds the term the instrument points at -- `encode::non_dct_surcharge`, | ||
| 39 | +`(EC_AV1_TXRD_LAMBDA - 1) * lambda * bits` charged to a non-`DCT_DCT` | ||
| 40 | +candidate only (the incumbent is always `DCT_DCT`, so the block's returned | ||
| 41 | +cost stays its true one). The intra decision now reads the same | ||
| 42 | +`EC_AV1_TXRD_LAMBDA` the inter one already did. Sweep below. | ||
| 43 | + | ||
| 44 | +## 2. `reduced_tx_set = 0`: the writer half, and the defect that blocks it | ||
| 45 | + | ||
| 46 | +Commit `95b4bee9`. The bit is read in ONE place on the writer side: | ||
| 47 | + | ||
| 48 | +* `Cdfs::reduced_tx_set` (default `true`) + `TxbSet::wide()` -- every luma | ||
| 49 | + set's `Set1` counterpart, transcribed from `decode::txbset_for` / | ||
| 50 | + `txbset_for_inter` / `inter_txbset_for`, applied at the top of `Cdfs::txb`. | ||
| 51 | + The `Set1` tables differ from their narrow twins in the `tx_type` field | ||
| 52 | + ONLY, so this is the whole writer-side map; the writer's symbol already | ||
| 53 | + comes from `decode::tx_type_symbol(cdf.len(), ..)`, so the wider alphabets | ||
| 54 | + need no writer change at all. The decoder never sets the field (it names the | ||
| 55 | + wide set itself; widening a wide set is the identity). | ||
| 56 | +* `encode::wide_tx_set(screen)` (`EC_AV1_TXSET_WIDE` = `0`/`screen`/`1`, | ||
| 57 | + `speed::WIDE_TX_SET` false at every preset) drives `header.reduced_tx_set` | ||
| 58 | + on both header sites, and the frame's `Cdfs` reads the header bit. | ||
| 59 | +* `encode::luma_set_for` gives the SEARCH and its pricer the same widened set, | ||
| 60 | + so the two agree on what a `tx_type` symbol costs. | ||
| 61 | +* Candidates: intra 8x8/4x4 get the seven-type `TX_SET_INTRA_1`; the twelve- | ||
| 62 | + and sixteen-type inter lists are written (the seven types both alphabets | ||
| 63 | + share) but NOT offered -- see below. | ||
| 64 | + | ||
| 65 | +BLOCKER, bisected: with the bit off, the encoder's own trial decode of the | ||
| 66 | +tile it just wrote (`filter_search::pick_filters` -> `decode_inter_frame_ | ||
| 67 | +tiles_lr`) desyncs and reads `BWDREF` on a frame that holds no such picture -- | ||
| 68 | +"a reference frame selected with no picture at this frame's own ref_frame_idx | ||
| 69 | +slot for it", refused out of `decode::ref_dims` (new probe: | ||
| 70 | +`EC_AV1_REFPROBE=1` prints the missing reference and the backtrace). Bisection: | ||
| 71 | + | ||
| 72 | +| arm | result | | ||
| 73 | +|---|---| | ||
| 74 | +| wide bit + both type searches OFF | PASS (witness + ffmpeg exact) | | ||
| 75 | +| wide bit + INTER search on, intra off | PASS | | ||
| 76 | +| wide bit + INTRA search on (7-type set) | **FAIL, the refusal above** | | ||
| 77 | +| wide bit off, `EC_AV1_TXRD_LAMBDA` 0/0.5/4 (cost perturbation alone) | PASS | | ||
| 78 | + | ||
| 79 | +So it is not RD noise and not the inter half: something in the SEVEN-type | ||
| 80 | +intra path writes a symbol the reader resolves differently. One real defect was | ||
| 81 | +found and fixed on the way (`decode_inter_frame_tiles_lr` hardcoded | ||
| 82 | +`reduced_tx_set = true` for the encoder's own trial decode -- the class its | ||
| 83 | +neighbours' doc comments name, a header bit a raw tile decode cannot guess); | ||
| 84 | +it is not the whole story, the desync survives it. | ||
| 85 | + | ||
| 86 | +`speed::WIDE_TX_SET` is therefore false at every preset and | ||
| 87 | +`EC_AV1_TXSET_WIDE` unset is byte-identical to main. | ||
| 88 | + | ||
| 89 | +## 3. The surcharge sweep (12-frame gate, `EC_AV1_TXSET=all`, film rows) | ||
| 90 | + | ||
| 91 | +BD-rate vs libaom `cpu-used 6` / rav1e `speed 6`, lower is better. Every arm is | ||
| 92 | +the UNCONDITIONAL intra search (the shipped default is screen-gated and | ||
| 93 | +byte-identical to the control on these rows). | ||
| 94 | + | ||
| 95 | +| clip | control | 1x (the plain arm) | 2x (`EC_AV1_TXRD_LAMBDA=2`) | 0.5x | | ||
| 96 | +|---|---|---|---|---| | ||
| 97 | +| bars 1080p | -1.0% / -16.8% | -2.3% / -17.8% | -1.2% / -16.9% | -0.8% / -16.5% | | ||
| 98 | +| film A | +21.7% / -4.4% | +22.1% / -4.0% | **+21.7% / -4.3%** | +22.3% / -3.9% | | ||
| 99 | + | ||
| 100 | +film A bytes: control 64392/102508/170169/413430, 1x 65201/103781/172167/419156 | ||
| 101 | +(+1.2..1.4%), 2x 64518/102989/170564/414763 (+0.2..0.3%), 0.5x | ||
| 102 | +64731/103742/171929/418934. The sweep is MONOTONE in the weight on both rows: | ||
| 103 | +0.5x spends more and loses more (film A +22.3/-3.9), 2x spends least and loses | ||
| 104 | +least. | ||
| 105 | + | ||
| 106 | +READING: the surcharge does exactly what the instrument predicted -- it buys | ||
| 107 | +the rate back (the arm's +1.3% of bytes collapses to +0.2%) and the film A row | ||
| 108 | +walks from +22.1/-4.0 to +21.7/-4.3, i.e. onto the control against libaom and | ||
| 109 | +0.1 SHORT of it against rav1e. It neutralises the loss; it does not turn it | ||
| 110 | +into a win, because what the search wins on film (0.02-0.06 dB) is smaller | ||
| 111 | +than what its symbols cost however they are priced. The same surcharge costs | ||
| 112 | +the bars row a point of its own gain (-2.3 -> -1.2), which is the sign that a | ||
| 113 | +single flat weight cannot serve both content classes. | ||
| 114 | + | ||
| 115 | +KEEP RULE: FAIL for the unconditional arm at every weight measured -- the rule | ||
| 116 | +wants both film rows DOWN, and the best weight lands film A ON the control. | ||
| 117 | +DECISION: the intra search stays SCREEN-GATED, the surcharge ships at its | ||
| 118 | +default weight of 1.0 (`non_dct_surcharge` returns 0, so every default stream | ||
| 119 | +is byte-identical to main), and `EC_AV1_TXRD_LAMBDA` stays the swept lever. | ||
| 120 | + | ||
| 121 | +## 4. Invariants, pins, suite | ||
| 122 | + | ||
| 123 | +Default state = every lever of this lane OFF (`WIDE_TX_SET` false at all | ||
| 124 | +presets, surcharge weight 1.0, the intra/inter searches on their own screen | ||
| 125 | +gates), so the shipped encoder is byte-identical to main -- which the pins | ||
| 126 | +make below. | ||
| 127 | + | ||
| 128 | +| invariant | preset 0 | preset 6 | | ||
| 129 | +|---|---|---| | ||
| 130 | +| `an_edge_clip_codes_every_reduced_set_tx_type_both_decoders_read_exactly` | PASS | PASS | | ||
| 131 | +| `an_inter_clip_codes_both_inter_set_tx_types_both_decoders_read_exactly` | PASS | PASS | | ||
| 132 | +| `the_facade_codes_the_same_bytes_as_encode_sequence` | PASS | PASS | | ||
| 133 | +| `predicted_coeff_bits_track_the_tile_the_writer_wrote` | PASS | PASS | | ||
| 134 | +| `tile_bytes_do_not_depend_on_the_thread_count --include-ignored` | PASS | PASS | | ||
| 135 | +| the three above under `EC_COMP_MISMATCH=1` (preset 0) | 0 mismatches | -- | | ||
| 136 | + | ||
| 137 | +`the_encoders_own_streams_are_byte_identical_to_their_pins`: PASS at the | ||
| 138 | +UNCHANGED 8562 / 33357, and again under `EC_AV1_TXSET=0 EC_AV1_TXSET_INTER=0`. | ||
| 139 | +`timeout 890 cargo check --workspace --all-targets -j4`: 0 errors, 0 `ec-av1` | ||
| 140 | +warnings (the 22 the workspace prints are `ec-opus`/`ec-vorbis`, untouched). | ||
| 141 | + | ||
| 142 | +`a_wide_tx_set_clip_codes_the_new_alphabets_both_decoders_read_exactly` is | ||
| 143 | +`#[ignore]`d with the blocker in its reason string -- it is the witness that | ||
| 144 | +closes section 2 the moment the desync is found. | ||
| 145 | + | ||
| 146 | +LONG-GOP: not re-run, and it does not need to be -- what ships changes no | ||
| 147 | +byte (pins unchanged, every lever off by default), so | ||
| 148 | +`bd_rate_film_long_gop` stands at the head's own +26.4/-6.6 (film A) and | ||
| 149 | ++89.8/+9.1 (film B). | ||
| 150 | + | ||
| 151 | +## 5. Deferred | ||
| 152 | + | ||
| 153 | +* `deferred: reduced_tx_set = 0 -- the writer half is BUILT and off by default; | ||
| 154 | + what blocks it is a desync between the seven-type intra path's writer and the | ||
| 155 | + encoder's own trial decode (section 2's bisection table), which shows up as a | ||
| 156 | + refused reference slot. What unblocks it: the first symbol where the trial | ||
| 157 | + decode's range diverges from the writer's (class equal-range-means-unread / | ||
| 158 | + compare-range-not-tell), on the two-frame witness that already reproduces it | ||
| 159 | + in 2 seconds -- one lane slot, no gate wall.` | ||
| 160 | +* `deferred: the twelve/sixteen-type INTER candidate lists -- written | ||
| 161 | + (encode::inter_tx_type_candidates' INTER_WIDE) but never offered, since the | ||
| 162 | + header bit they need is the blocked one above. Unblocked by the same fix.` | ||
| 163 | +* `deferred: the reference-aware type cost the charter asked for -- NOT BUILT, | ||
| 164 | + and deliberately: the per-plane per-frame instrument (section 1) shows the | ||
| 165 | + arm equal-or-better on the key frame AND every leaf, so there is no | ||
| 166 | + propagation signal for such a term to price. What would revive it: a content | ||
| 167 | + class whose leaves DO decay under the arm.` | ||
| 168 | +* `deferred: the surcharge as a per-content lever (screen 1.0, film 2.0) -- | ||
| 169 | + measured on film A only; film B and the capture were not swept. Unblocked by | ||
| 170 | + two more gate slots. As a flat default it is a wash, which is why it ships | ||
| 171 | + at 1.0.` | ||
| 172 | +* `deferred: EC_AV1_REFPROBE=1 is a new decoder-side probe (the missing | ||
| 173 | + reference slot plus a backtrace); it is env-gated and costs a branch on an | ||
| 174 | + error path only.` | ||