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 {
3846738467
3846838468 #[test]
3846938469 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)
3847138471 for (w, h) in [(128usize, 128usize), (192, 128)] {
3847238472 round_trips(w, h, &[DC_PRED as u8], fctx);
3847338473 }
@@ -38479,7 +38479,7 @@ mod tests {
3847938479 /// decoder round adds, not just `DC_PRED`.
3848038480 #[test]
3848138481 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)
3848338483 for (w, h) in [(128usize, 128usize), (192, 128)] {
3848438484 round_trips(w, h, &crate::intra::KEY_FRAME_MODES, fctx);
3848538485 }
@@ -38490,7 +38490,7 @@ mod tests {
3849038490 /// this decoder round adds.
3849138491 #[test]
3849238492 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
3849438494 for (w, h) in [(854usize, 480usize), (216, 96)] {
3849538495 round_trips(w, h, &crate::intra::KEY_FRAME_MODES, fctx);
3849638496 }
@@ -38504,7 +38504,7 @@ mod tests {
3850438504 /// bit, `partition_w8` leaves).
3850538505 #[test]
3850638506 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)
3850838508 for (w, h) in [(40usize, 32usize), (640, 360)] {
3850938509 round_trips(w, h, &crate::intra::KEY_FRAME_MODES, fctx);
3851038510 }
@@ -38800,7 +38800,7 @@ mod tests {
3880038800 /// crate's own writer and reader could otherwise share.
3880138801 #[test]
3880238802 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)
3880438804 if !have_ffmpeg() {
3880538805 eprintln!("SKIP ffmpeg_and_this_decoder_agree_on_a_key_frame: no ffmpeg");
3880638806 return;
@@ -38847,7 +38847,7 @@ mod tests {
3884738847 /// between the palette colours and the colour-index maps).
3884838848 #[test]
3884938849 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)
3885138851 if !crate::encode::filter_intra_on() {
3885238852 eprintln!("SKIP a_filter_intra_key_frame...: EC_AV1_FILTER_INTRA=0");
3885338853 return;
@@ -38917,7 +38917,7 @@ mod tests {
3891738917 /// wire).
3891838918 #[test]
3891938919 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
3892138921 use crate::encode::encode_key_frame_with_ctx;
3892238922 let (width, height) = (64usize, 64usize);
3892338923 let picture = round_trip_test_card(width, height);
@@ -39117,7 +39117,7 @@ mod tests {
3911739117
3911839118 #[test]
3911939119 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)
3912139121 gop_round_trips(128, 64, fctx);
3912239122 }
3912339123
@@ -39126,7 +39126,7 @@ mod tests {
3912639126 /// split path is exercised too.
3912739127 #[test]
3912839128 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)
3913039130 gop_round_trips(216, 96, fctx);
3913139131 }
3913239132
@@ -39356,7 +39356,7 @@ mod tests {
3935639356
3935739357 #[test]
3935839358 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)
3936039360 if !have_ffmpeg() {
3936139361 eprintln!("SKIP ffmpeg_and_this_decoder_agree_on_a_gop: no ffmpeg");
3936239362 return;
crates/ec-av1/src/encode.rsmodified+12 -1
@@ -722,6 +722,17 @@ pub fn take_b64_root_hits() -> usize {
722722 B64_HITS.swap(0, std::sync::atomic::Ordering::Relaxed)
723723 }
724724
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+
725736 /// How many 128x128 `PARTITION_NONE` roots the search took since the last
726737 /// [`take_b128_none_hits`] (class `gate-blind-to-feature`): a flat BD result
727738 /// is only attributable once the fire count is known.
@@ -11638,7 +11649,7 @@ pub(crate) fn encode_inter_frame(
1163811649 // 128x128 candidate is weighed.
1163911650 let mark128 = blocks.len();
1164011651 let mut root_cost = 0.0f64;
11641- let root128 = sb128_search
11652+ let root128 = (sb128_search && b128_root() && cells.len() == 4)
1164211653 .then(|| search_root_128(
1164311654 &mut luma,
1164411655 &mut chroma,