From a3b3ee439f8d962ca8dd7eb1aad2c33fab2ca41a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Mon, 7 Sep 2026 22:45:20 +0300 Subject: [PATCH] test(av1): witness that every reduced-set tx_type fires and both decoders read it exactly --- crates/ec-av1/src/encode.rs | 1 + crates/ec-av1/src/encoder.rs | 91 ++++++++++++++++++++++++++++++++++++ crates/ec-av1/src/tile.rs | 5 +- 3 files changed, 95 insertions(+), 2 deletions(-) diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index e4f87479..fe234028 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -11910,6 +11910,7 @@ mod tests { let (_, inter_header) = inter_frame_headers(width, height, 100, 1, 0).unwrap(); let residual_block = BlockCoeffs { + luma_tx_types: Vec::new(), angle_delta_y: 0, cfl_alphas: None, filter_intra: None, diff --git a/crates/ec-av1/src/encoder.rs b/crates/ec-av1/src/encoder.rs index 15728108..578ef78f 100644 --- a/crates/ec-av1/src/encoder.rs +++ b/crates/ec-av1/src/encoder.rs @@ -3615,6 +3615,97 @@ mod tests { eprintln!("delta_q witness: {levels} quantizer levels, {} bytes", stream.len()); } + /// lane-txset's witness: a clip of hard directional edges makes the intra + /// luma search take EVERY type of the five-type reduced set + /// (`TX_SET_INTRA_2`: `DCT_DCT`, `ADST_ADST`, `ADST_DCT`, `DCT_ADST`, + /// `IDTX`) at least once -- the fire count, class `gate-blind-to-feature` + /// -- and both decoders reconstruct every frame sample-exact from the + /// `tx_type` symbols that name them. Before the lane the writer coded + /// `DCT_DCT` for every luma transform unit ever written, so this is also + /// the statement that the other four are REACHABLE at all. + #[test] + fn an_edge_clip_codes_every_reduced_set_tx_type_both_decoders_read_exactly() { + let _knobs = crate::speed::knob_read(); + let _gate_lock = crate::stream::tests::lock_gate_counters(); + let (width, height) = (320usize, 192usize); + // Sharp horizontal and vertical steps: a vertical edge is what an + // `ADST` column pass beats a `DCT` one on, a horizontal edge the + // mirror, and the flat/ramp areas between them are where `IDTX` wins. + let sources: Vec = (0..2) + .map(|t| { + let mut p = test_card(width, height, t * 3); + for y in 0..height { + for x in 0..width { + let v = match ((x + t * 4) / 16 % 2, y / 16 % 2) { + (0, 0) => 16u16, + (1, 0) => 235, + (0, 1) => (x % 64 * 3) as u16, + _ => (y % 64 * 3) as u16, + }; + p.y[y * width + x] = v; + } + } + p + }) + .collect(); + let config = EncoderConfig { + width, + height, + base_q_idx: 90, + gop: 2, + colour: Colour::Bt709Limited, + tile_cols_log2: 0, + tile_rows_log2: 0, + }; + let mut enc = Av1Encoder::new(config).unwrap(); + let _ = crate::encode::take_tx_type_hits(); + let mut stream = Vec::new(); + for packet in encode_all(&mut enc, &sources) { + stream.extend_from_slice(&packet.data); + } + let hits = crate::encode::take_tx_type_hits(); + // The type search is a speed lever (`speed::TX_TYPE_SEARCH`); above + // the presets that carry it only `DCT_DCT` is offered, and the + // exactness half below is what still runs there. + if crate::speed::at(&crate::speed::TX_TYPE_SEARCH) { + for (name, ty) in [ + ("DCT_DCT", crate::transform::TxType::DctDct), + ("ADST_ADST", crate::transform::TxType::AdstAdst), + ("ADST_DCT", crate::transform::TxType::AdstDct), + ("DCT_ADST", crate::transform::TxType::DctAdst), + ("IDTX", crate::transform::TxType::Idtx), + ] { + assert!( + hits[ty as usize] > 0, + "no luma transform unit took {name}: {hits:?}" + ); + } + } else { + eprintln!("SKIP the fire count at preset {}: no type search", crate::speed::speed()); + } + let ours = crate::stream::decode_stream(&stream).expect("our decoder"); + assert_eq!(ours.len(), sources.len(), "our decoder's frames"); + if have_ffmpeg() { + let theirs = ffmpeg_decode_luma(&stream, width, height); + assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); + for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { + let got: Vec = a.y.iter().map(|&v| v as u8).collect(); + if let Some(at) = got.iter().zip(b).position(|(x, y)| x != y) { + panic!( + "frame {i}: luma differs first at ({}, {}): ours {} vs ffmpeg {}", + at % width, + at / width, + got[at], + b[at], + ); + } + } + } else { + eprintln!("SKIP the ffmpeg half: no ffmpeg"); + } + eprintln!("tx_type witness: hits {hits:?}, {} bytes", stream.len()); + } + /// Every SHIPPED SPEED PRESET codes a stream both decoders reconstruct /// sample-exact -- ours and ffmpeg's -- and codes a DIFFERENT stream from /// its neighbour (a preset that changes no byte is a preset that buys no diff --git a/crates/ec-av1/src/tile.rs b/crates/ec-av1/src/tile.rs index d69e61b0..40875e3f 100644 --- a/crates/ec-av1/src/tile.rs +++ b/crates/ec-av1/src/tile.rs @@ -8005,6 +8005,7 @@ mod tests { 0, 0, None, + TxType::DctDct, ); priced += luma_32_coeff_bits(grid); } @@ -8953,7 +8954,7 @@ mod tests { .sum(); d + lambda * coeff_bits(grid, set, crate::decode::q_ctx_of(q), 0, 0) }; - let bits = rdoq(&mut levels, &scaled, side, q, set, 0, 0, lambda); + let bits = rdoq(&mut levels, &scaled, side, q, set, 0, 0, lambda, TxType::DctDct); assert_eq!(bits, coeff_bits(&levels, set, crate::decode::q_ctx_of(q), 0, 0)); assert!(cost(&levels) <= cost(&before), "{:?} vs {:?}", cost(&levels), cost(&before)); // The tail is what it is for: the last coded position moves earlier. @@ -8974,7 +8975,7 @@ mod tests { if v < 0.0 { -l } else { l } }) .collect(); - let bits = rdoq(&mut levels, &scaled, side, q, set, 0, 0, lambda); + let bits = rdoq(&mut levels, &scaled, side, q, set, 0, 0, lambda, TxType::DctDct); let corner: Vec = (0..32) .flat_map(|row| levels[row * side..][..32].to_vec()) .collect();