forge
Explore
Log in

Don't you dare go Hollow

Ten decode round-trip tests decoded their own encoder's stream at the wrong superblock size

Browse files at this commit

330a2dfb7ee6e62291608cdb87543a0c5a464e5cAhmet Kaan GümüşParent: cfb8167
  • fix
    • ten decode round-trip tests decoded their own encoder's stream at the wrong superblock size
Show full message
fix(av1): ten decode round-trip tests decoded their own encoder's stream at the wrong superblock size

Every one of them encodes with this process's encoder and then decodes
the tile directly with a plain FrameCtx, whose superblock size is the
decoder default (64) rather than the size the writer used -- so with 128
superblocks on, the reader skipped the root's partition symbol and the
whole tile desynced. FrameCtx::for_encoder exists for exactly this
(stale-header class, the same shape as the filter_intra_on argument
beside it). Swept the module: two more tests had the same defect without
failing yet. EC_AV1_B128=0 attribution knob added.
crates/ec-av1/src/decode.rsmodified+10 -10
@@ -38467,7 +38467,7 @@ mod tests {
38467 38467
38468 #[test]38468 #[test]
38469 fn real_yuv_round_trips_bit_exact_against_the_encoder_reconstruction() {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 for (w, h) in [(128usize, 128usize), (192, 128)] {38471 for (w, h) in [(128usize, 128usize), (192, 128)] {
38472 round_trips(w, h, &[DC_PRED as u8], fctx);38472 round_trips(w, h, &[DC_PRED as u8], fctx);
38473 }38473 }
@@ -38479,7 +38479,7 @@ mod tests {
38479 /// decoder round adds, not just `DC_PRED`.38479 /// decoder round adds, not just `DC_PRED`.
38480 #[test]38480 #[test]
38481 fn every_intra_mode_round_trips_bit_exact_against_the_encoder_reconstruction() {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 for (w, h) in [(128usize, 128usize), (192, 128)] {38483 for (w, h) in [(128usize, 128usize), (192, 128)] {
38484 round_trips(w, h, &crate::intra::KEY_FRAME_MODES, fctx);38484 round_trips(w, h, &crate::intra::KEY_FRAME_MODES, fctx);
38485 }38485 }
@@ -38490,7 +38490,7 @@ mod tests {
38490 /// this decoder round adds.38490 /// this decoder round adds.
38491 #[test]38491 #[test]
38492 fn odd_sizes_round_trip_bit_exact_against_the_encoder_reconstruction() {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 for (w, h) in [(854usize, 480usize), (216, 96)] {38494 for (w, h) in [(854usize, 480usize), (216, 96)] {
38495 round_trips(w, h, &crate::intra::KEY_FRAME_MODES, fctx);38495 round_trips(w, h, &crate::intra::KEY_FRAME_MODES, fctx);
38496 }38496 }
@@ -38504,7 +38504,7 @@ mod tests {
38504 /// bit, `partition_w8` leaves).38504 /// bit, `partition_w8` leaves).
38505 #[test]38505 #[test]
38506 fn leaf8_straddle_sizes_round_trip_bit_exact_against_the_encoder_reconstruction() {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 for (w, h) in [(40usize, 32usize), (640, 360)] {38508 for (w, h) in [(40usize, 32usize), (640, 360)] {
38509 round_trips(w, h, &crate::intra::KEY_FRAME_MODES, fctx);38509 round_trips(w, h, &crate::intra::KEY_FRAME_MODES, fctx);
38510 }38510 }
@@ -38800,7 +38800,7 @@ mod tests {
38800 /// crate's own writer and reader could otherwise share.38800 /// crate's own writer and reader could otherwise share.
38801 #[test]38801 #[test]
38802 fn ffmpeg_and_this_decoder_agree_on_a_key_frame() {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 if !have_ffmpeg() {38804 if !have_ffmpeg() {
38805 eprintln!("SKIP ffmpeg_and_this_decoder_agree_on_a_key_frame: no ffmpeg");38805 eprintln!("SKIP ffmpeg_and_this_decoder_agree_on_a_key_frame: no ffmpeg");
38806 return;38806 return;
@@ -38847,7 +38847,7 @@ mod tests {
38847 /// between the palette colours and the colour-index maps).38847 /// between the palette colours and the colour-index maps).
38848 #[test]38848 #[test]
38849 fn a_filter_intra_key_frame_decodes_pixel_exact_through_ffmpeg() {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 if !crate::encode::filter_intra_on() {38851 if !crate::encode::filter_intra_on() {
38852 eprintln!("SKIP a_filter_intra_key_frame...: EC_AV1_FILTER_INTRA=0");38852 eprintln!("SKIP a_filter_intra_key_frame...: EC_AV1_FILTER_INTRA=0");
38853 return;38853 return;
@@ -38917,7 +38917,7 @@ mod tests {
38917 /// wire).38917 /// wire).
38918 #[test]38918 #[test]
38919 fn a_key_frames_tile_needs_the_headers_own_tx_select_bit() {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 use crate::encode::encode_key_frame_with_ctx;38921 use crate::encode::encode_key_frame_with_ctx;
38922 let (width, height) = (64usize, 64usize);38922 let (width, height) = (64usize, 64usize);
38923 let picture = round_trip_test_card(width, height);38923 let picture = round_trip_test_card(width, height);
@@ -39117,7 +39117,7 @@ mod tests {
39117 39117
39118 #[test]39118 #[test]
39119 fn a_gop_round_trips_bit_exact_against_the_encoder_reconstruction() {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 gop_round_trips(128, 64, fctx);39121 gop_round_trips(128, 64, fctx);
39122 }39122 }
39123 39123
@@ -39126,7 +39126,7 @@ mod tests {
39126 /// split path is exercised too.39126 /// split path is exercised too.
39127 #[test]39127 #[test]
39128 fn an_odd_size_gop_round_trips_bit_exact_against_the_encoder_reconstruction() {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 gop_round_trips(216, 96, fctx);39130 gop_round_trips(216, 96, fctx);
39131 }39131 }
39132 39132
@@ -39356,7 +39356,7 @@ mod tests {
39356 39356
39357 #[test]39357 #[test]
39358 fn ffmpeg_and_this_decoder_agree_on_a_gop() {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 if !have_ffmpeg() {39360 if !have_ffmpeg() {
39361 eprintln!("SKIP ffmpeg_and_this_decoder_agree_on_a_gop: no ffmpeg");39361 eprintln!("SKIP ffmpeg_and_this_decoder_agree_on_a_gop: no ffmpeg");
39362 return;39362 return;
crates/ec-av1/src/encode.rsmodified+12 -1
@@ -722,6 +722,17 @@ pub fn take_b64_root_hits() -> usize {
722 B64_HITS.swap(0, std::sync::atomic::Ordering::Relaxed)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 /// How many 128x128 `PARTITION_NONE` roots the search took since the last736 /// How many 128x128 `PARTITION_NONE` roots the search took since the last
726 /// [`take_b128_none_hits`] (class `gate-blind-to-feature`): a flat BD result737 /// [`take_b128_none_hits`] (class `gate-blind-to-feature`): a flat BD result
727 /// is only attributable once the fire count is known.738 /// is only attributable once the fire count is known.
@@ -11638,7 +11649,7 @@ pub(crate) fn encode_inter_frame(
11638 // 128x128 candidate is weighed.11649 // 128x128 candidate is weighed.
11639 let mark128 = blocks.len();11650 let mark128 = blocks.len();
11640 let mut root_cost = 0.0f64;11651 let mut root_cost = 0.0f64;
11641- let root128 = sb128_search11652+ let root128 = (sb128_search && b128_root() && cells.len() == 4)
11642 .then(|| search_root_128(11653 .then(|| search_root_128(
11643 &mut luma,11654 &mut luma,
11644 &mut chroma,11655 &mut chroma,