Ten decode round-trip tests decoded their own encoder's stream at the wrong superblock size
Browse files at this commit330a2dfb7ee6e62291608cdb87543a0c5a464e5cParent: cfb8167- fix
- ten decode round-trip tests decoded their own encoder's stream at the wrong superblock size
2 changed files +22 -11
- crates/ec-av1/src/decode.rs +10 -10
- crates/ec-av1/src/encode.rs +12 -1
crates/ec-av1/src/decode.rsmodified+10 -10
| @@ -38467,7 +38467,7 @@ mod tests { | ||
| 38467 | 38467 | |
| 38468 | 38468 | #[test] |
| 38469 | 38469 | fn real_yuv_round_trips_bit_exact_against_the_encoder_reconstruction() { |
| 38470 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 38470 | + let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: this test ENCODES, so its decode context starts at the superblock size this process encodes at (stale-header class, as `filter_intra_on` below) | |
| 38471 | 38471 | for (w, h) in [(128usize, 128usize), (192, 128)] { |
| 38472 | 38472 | round_trips(w, h, &[DC_PRED as u8], fctx); |
| 38473 | 38473 | } |
| @@ -38479,7 +38479,7 @@ mod tests { | ||
| 38479 | 38479 | /// decoder round adds, not just `DC_PRED`. |
| 38480 | 38480 | #[test] |
| 38481 | 38481 | fn every_intra_mode_round_trips_bit_exact_against_the_encoder_reconstruction() { |
| 38482 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 38482 | + let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: this test ENCODES, so its decode context starts at the superblock size this process encodes at (stale-header class, as `filter_intra_on` below) | |
| 38483 | 38483 | for (w, h) in [(128usize, 128usize), (192, 128)] { |
| 38484 | 38484 | round_trips(w, h, &crate::intra::KEY_FRAME_MODES, fctx); |
| 38485 | 38485 | } |
| @@ -38490,7 +38490,7 @@ mod tests { | ||
| 38490 | 38490 | /// this decoder round adds. |
| 38491 | 38491 | #[test] |
| 38492 | 38492 | fn odd_sizes_round_trip_bit_exact_against_the_encoder_reconstruction() { |
| 38493 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 38493 | + let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: encodes, so the decode context takes this process's superblock size | |
| 38494 | 38494 | for (w, h) in [(854usize, 480usize), (216, 96)] { |
| 38495 | 38495 | round_trips(w, h, &crate::intra::KEY_FRAME_MODES, fctx); |
| 38496 | 38496 | } |
| @@ -38504,7 +38504,7 @@ mod tests { | ||
| 38504 | 38504 | /// bit, `partition_w8` leaves). |
| 38505 | 38505 | #[test] |
| 38506 | 38506 | fn leaf8_straddle_sizes_round_trip_bit_exact_against_the_encoder_reconstruction() { |
| 38507 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 38507 | + let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: this test ENCODES, so its decode context starts at the superblock size this process encodes at (stale-header class, as `filter_intra_on` below) | |
| 38508 | 38508 | for (w, h) in [(40usize, 32usize), (640, 360)] { |
| 38509 | 38509 | round_trips(w, h, &crate::intra::KEY_FRAME_MODES, fctx); |
| 38510 | 38510 | } |
| @@ -38800,7 +38800,7 @@ mod tests { | ||
| 38800 | 38800 | /// crate's own writer and reader could otherwise share. |
| 38801 | 38801 | #[test] |
| 38802 | 38802 | fn ffmpeg_and_this_decoder_agree_on_a_key_frame() { |
| 38803 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 38803 | + let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: this test ENCODES, so its decode context starts at the superblock size this process encodes at (stale-header class, as `filter_intra_on` below) | |
| 38804 | 38804 | if !have_ffmpeg() { |
| 38805 | 38805 | eprintln!("SKIP ffmpeg_and_this_decoder_agree_on_a_key_frame: no ffmpeg"); |
| 38806 | 38806 | return; |
| @@ -38847,7 +38847,7 @@ mod tests { | ||
| 38847 | 38847 | /// between the palette colours and the colour-index maps). |
| 38848 | 38848 | #[test] |
| 38849 | 38849 | fn a_filter_intra_key_frame_decodes_pixel_exact_through_ffmpeg() { |
| 38850 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 38850 | + let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: this test ENCODES, so its decode context starts at the superblock size this process encodes at (stale-header class, as `filter_intra_on` below) | |
| 38851 | 38851 | if !crate::encode::filter_intra_on() { |
| 38852 | 38852 | eprintln!("SKIP a_filter_intra_key_frame...: EC_AV1_FILTER_INTRA=0"); |
| 38853 | 38853 | return; |
| @@ -38917,7 +38917,7 @@ mod tests { | ||
| 38917 | 38917 | /// wire). |
| 38918 | 38918 | #[test] |
| 38919 | 38919 | fn a_key_frames_tile_needs_the_headers_own_tx_select_bit() { |
| 38920 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 38920 | + let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: encodes, so the decode context takes this process's superblock size | |
| 38921 | 38921 | use crate::encode::encode_key_frame_with_ctx; |
| 38922 | 38922 | let (width, height) = (64usize, 64usize); |
| 38923 | 38923 | let picture = round_trip_test_card(width, height); |
| @@ -39117,7 +39117,7 @@ mod tests { | ||
| 39117 | 39117 | |
| 39118 | 39118 | #[test] |
| 39119 | 39119 | fn a_gop_round_trips_bit_exact_against_the_encoder_reconstruction() { |
| 39120 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 39120 | + let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: this test ENCODES, so its decode context starts at the superblock size this process encodes at (stale-header class, as `filter_intra_on` below) | |
| 39121 | 39121 | gop_round_trips(128, 64, fctx); |
| 39122 | 39122 | } |
| 39123 | 39123 | |
| @@ -39126,7 +39126,7 @@ mod tests { | ||
| 39126 | 39126 | /// split path is exercised too. |
| 39127 | 39127 | #[test] |
| 39128 | 39128 | fn an_odd_size_gop_round_trips_bit_exact_against_the_encoder_reconstruction() { |
| 39129 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 39129 | + let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: this test ENCODES, so its decode context starts at the superblock size this process encodes at (stale-header class, as `filter_intra_on` below) | |
| 39130 | 39130 | gop_round_trips(216, 96, fctx); |
| 39131 | 39131 | } |
| 39132 | 39132 | |
| @@ -39356,7 +39356,7 @@ mod tests { | ||
| 39356 | 39356 | |
| 39357 | 39357 | #[test] |
| 39358 | 39358 | fn ffmpeg_and_this_decoder_agree_on_a_gop() { |
| 39359 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 39359 | + let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: this test ENCODES, so its decode context starts at the superblock size this process encodes at (stale-header class, as `filter_intra_on` below) | |
| 39360 | 39360 | if !have_ffmpeg() { |
| 39361 | 39361 | eprintln!("SKIP ffmpeg_and_this_decoder_agree_on_a_gop: no ffmpeg"); |
| 39362 | 39362 | return; |
crates/ec-av1/src/encode.rsmodified+12 -1
| @@ -722,6 +722,17 @@ pub fn take_b64_root_hits() -> usize { | ||
| 722 | 722 | B64_HITS.swap(0, std::sync::atomic::Ordering::Relaxed) |
| 723 | 723 | } |
| 724 | 724 | |
| 725 | +/// Whether the 128 superblock root offers its `PARTITION_NONE` candidate at | |
| 726 | +/// all ([`search_root_128`]). On by default; `EC_AV1_B128=0` turns it off, | |
| 727 | +/// which is the attribution arm for a 128-superblock stream: it separates | |
| 728 | +/// what the SIZE costs from what the 128x128 BLOCK buys. | |
| 729 | +fn b128_root() -> bool { | |
| 730 | + static ENV: std::sync::LazyLock<bool> = std::sync::LazyLock::new(|| { | |
| 731 | + crate::envflags::var("EC_AV1_B128").ok().is_none_or(|v| v != "0") | |
| 732 | + }); | |
| 733 | + *ENV | |
| 734 | +} | |
| 735 | + | |
| 725 | 736 | /// How many 128x128 `PARTITION_NONE` roots the search took since the last |
| 726 | 737 | /// [`take_b128_none_hits`] (class `gate-blind-to-feature`): a flat BD result |
| 727 | 738 | /// is only attributable once the fire count is known. |
| @@ -11638,7 +11649,7 @@ pub(crate) fn encode_inter_frame( | ||
| 11638 | 11649 | // 128x128 candidate is weighed. |
| 11639 | 11650 | let mark128 = blocks.len(); |
| 11640 | 11651 | let mut root_cost = 0.0f64; |
| 11641 | - let root128 = sb128_search | |
| 11652 | + let root128 = (sb128_search && b128_root() && cells.len() == 4) | |
| 11642 | 11653 | .then(|| search_root_128( |
| 11643 | 11654 | &mut luma, |
| 11644 | 11655 | &mut chroma, |