Witness that every reduced-set tx_type fires and both decoders read it exactly
Browse files at this commita3b3ee439f8d962ca8dd7eb1aad2c33fab2ca41aParent: 2fd2ac4- test
- witness that every reduced-set tx_type fires and both decoders read it exactly
3 changed files +95 -2
crates/ec-av1/src/encode.rsmodified+1 -0
| @@ -11910,6 +11910,7 @@ mod tests { | |||
| 11910 | let (_, inter_header) = inter_frame_headers(width, height, 100, 1, 0).unwrap(); | 11910 | let (_, inter_header) = inter_frame_headers(width, height, 100, 1, 0).unwrap(); |
| 11911 | 11911 | ||
| 11912 | let residual_block = BlockCoeffs { | 11912 | let residual_block = BlockCoeffs { |
| 11913 | + luma_tx_types: Vec::new(), | ||
| 11913 | angle_delta_y: 0, | 11914 | angle_delta_y: 0, |
| 11914 | cfl_alphas: None, | 11915 | cfl_alphas: None, |
| 11915 | filter_intra: None, | 11916 | filter_intra: None, |
crates/ec-av1/src/encoder.rsmodified+91 -0
| @@ -3615,6 +3615,97 @@ mod tests { | |||
| 3615 | eprintln!("delta_q witness: {levels} quantizer levels, {} bytes", stream.len()); | 3615 | eprintln!("delta_q witness: {levels} quantizer levels, {} bytes", stream.len()); |
| 3616 | } | 3616 | } |
| 3617 | 3617 | ||
| 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 | + let _knobs = crate::speed::knob_read(); | ||
| 3629 | + let _gate_lock = crate::stream::tests::lock_gate_counters(); | ||
| 3630 | + let (width, height) = (320usize, 192usize); | ||
| 3631 | + // Sharp horizontal and vertical steps: a vertical edge is what an | ||
| 3632 | + // `ADST` column pass beats a `DCT` one on, a horizontal edge the | ||
| 3633 | + // mirror, and the flat/ramp areas between them are where `IDTX` wins. | ||
| 3634 | + let sources: Vec<Picture> = (0..2) | ||
| 3635 | + .map(|t| { | ||
| 3636 | + let mut p = test_card(width, height, t * 3); | ||
| 3637 | + for y in 0..height { | ||
| 3638 | + for x in 0..width { | ||
| 3639 | + let v = match ((x + t * 4) / 16 % 2, y / 16 % 2) { | ||
| 3640 | + (0, 0) => 16u16, | ||
| 3641 | + (1, 0) => 235, | ||
| 3642 | + (0, 1) => (x % 64 * 3) as u16, | ||
| 3643 | + _ => (y % 64 * 3) as u16, | ||
| 3644 | + }; | ||
| 3645 | + p.y[y * width + x] = v; | ||
| 3646 | + } | ||
| 3647 | + } | ||
| 3648 | + p | ||
| 3649 | + }) | ||
| 3650 | + .collect(); | ||
| 3651 | + let config = EncoderConfig { | ||
| 3652 | + width, | ||
| 3653 | + height, | ||
| 3654 | + base_q_idx: 90, | ||
| 3655 | + gop: 2, | ||
| 3656 | + colour: Colour::Bt709Limited, | ||
| 3657 | + tile_cols_log2: 0, | ||
| 3658 | + tile_rows_log2: 0, | ||
| 3659 | + }; | ||
| 3660 | + let mut enc = Av1Encoder::new(config).unwrap(); | ||
| 3661 | + let _ = crate::encode::take_tx_type_hits(); | ||
| 3662 | + let mut stream = Vec::new(); | ||
| 3663 | + for packet in encode_all(&mut enc, &sources) { | ||
| 3664 | + stream.extend_from_slice(&packet.data); | ||
| 3665 | + } | ||
| 3666 | + let hits = crate::encode::take_tx_type_hits(); | ||
| 3667 | + // The type search is a speed lever (`speed::TX_TYPE_SEARCH`); above | ||
| 3668 | + // the presets that carry it only `DCT_DCT` is offered, and the | ||
| 3669 | + // exactness half below is what still runs there. | ||
| 3670 | + if crate::speed::at(&crate::speed::TX_TYPE_SEARCH) { | ||
| 3671 | + for (name, ty) in [ | ||
| 3672 | + ("DCT_DCT", crate::transform::TxType::DctDct), | ||
| 3673 | + ("ADST_ADST", crate::transform::TxType::AdstAdst), | ||
| 3674 | + ("ADST_DCT", crate::transform::TxType::AdstDct), | ||
| 3675 | + ("DCT_ADST", crate::transform::TxType::DctAdst), | ||
| 3676 | + ("IDTX", crate::transform::TxType::Idtx), | ||
| 3677 | + ] { | ||
| 3678 | + assert!( | ||
| 3679 | + hits[ty as usize] > 0, | ||
| 3680 | + "no luma transform unit took {name}: {hits:?}" | ||
| 3681 | + ); | ||
| 3682 | + } | ||
| 3683 | + } else { | ||
| 3684 | + eprintln!("SKIP the fire count at preset {}: no type search", crate::speed::speed()); | ||
| 3685 | + } | ||
| 3686 | + let ours = crate::stream::decode_stream(&stream).expect("our decoder"); | ||
| 3687 | + assert_eq!(ours.len(), sources.len(), "our decoder's frames"); | ||
| 3688 | + if have_ffmpeg() { | ||
| 3689 | + let theirs = ffmpeg_decode_luma(&stream, width, height); | ||
| 3690 | + assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); | ||
| 3691 | + for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { | ||
| 3692 | + let got: Vec<u8> = a.y.iter().map(|&v| v as u8).collect(); | ||
| 3693 | + if let Some(at) = got.iter().zip(b).position(|(x, y)| x != y) { | ||
| 3694 | + panic!( | ||
| 3695 | + "frame {i}: luma differs first at ({}, {}): ours {} vs ffmpeg {}", | ||
| 3696 | + at % width, | ||
| 3697 | + at / width, | ||
| 3698 | + got[at], | ||
| 3699 | + b[at], | ||
| 3700 | + ); | ||
| 3701 | + } | ||
| 3702 | + } | ||
| 3703 | + } else { | ||
| 3704 | + eprintln!("SKIP the ffmpeg half: no ffmpeg"); | ||
| 3705 | + } | ||
| 3706 | + eprintln!("tx_type witness: hits {hits:?}, {} bytes", stream.len()); | ||
| 3707 | + } | ||
| 3708 | + | ||
| 3618 | /// Every SHIPPED SPEED PRESET codes a stream both decoders reconstruct | 3709 | /// Every SHIPPED SPEED PRESET codes a stream both decoders reconstruct |
| 3619 | /// sample-exact -- ours and ffmpeg's -- and codes a DIFFERENT stream from | 3710 | /// sample-exact -- ours and ffmpeg's -- and codes a DIFFERENT stream from |
| 3620 | /// its neighbour (a preset that changes no byte is a preset that buys no | 3711 | /// its neighbour (a preset that changes no byte is a preset that buys no |
crates/ec-av1/src/tile.rsmodified+3 -2
| @@ -8005,6 +8005,7 @@ mod tests { | |||
| 8005 | 0, | 8005 | 0, |
| 8006 | 0, | 8006 | 0, |
| 8007 | None, | 8007 | None, |
| 8008 | + TxType::DctDct, | ||
| 8008 | ); | 8009 | ); |
| 8009 | priced += luma_32_coeff_bits(grid); | 8010 | priced += luma_32_coeff_bits(grid); |
| 8010 | } | 8011 | } |
| @@ -8953,7 +8954,7 @@ mod tests { | |||
| 8953 | .sum(); | 8954 | .sum(); |
| 8954 | d + lambda * coeff_bits(grid, set, crate::decode::q_ctx_of(q), 0, 0) | 8955 | d + lambda * coeff_bits(grid, set, crate::decode::q_ctx_of(q), 0, 0) |
| 8955 | }; | 8956 | }; |
| 8956 | - 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); |
| 8957 | assert_eq!(bits, coeff_bits(&levels, set, crate::decode::q_ctx_of(q), 0, 0)); | 8958 | assert_eq!(bits, coeff_bits(&levels, set, crate::decode::q_ctx_of(q), 0, 0)); |
| 8958 | assert!(cost(&levels) <= cost(&before), "{:?} vs {:?}", cost(&levels), cost(&before)); | 8959 | assert!(cost(&levels) <= cost(&before), "{:?} vs {:?}", cost(&levels), cost(&before)); |
| 8959 | // The tail is what it is for: the last coded position moves earlier. | 8960 | // The tail is what it is for: the last coded position moves earlier. |
| @@ -8974,7 +8975,7 @@ mod tests { | |||
| 8974 | if v < 0.0 { -l } else { l } | 8975 | if v < 0.0 { -l } else { l } |
| 8975 | }) | 8976 | }) |
| 8976 | .collect(); | 8977 | .collect(); |
| 8977 | - 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); |
| 8978 | let corner: Vec<i32> = (0..32) | 8979 | let corner: Vec<i32> = (0..32) |
| 8979 | .flat_map(|row| levels[row * side..][..32].to_vec()) | 8980 | .flat_map(|row| levels[row * side..][..32].to_vec()) |
| 8980 | .collect(); | 8981 | .collect(); |