diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 0e85784a..c7efe131 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -38467,7 +38467,7 @@ mod tests { #[test] fn real_yuv_round_trips_bit_exact_against_the_encoder_reconstruction() { - let fctx = &crate::decode::FrameCtx::new(); + 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) for (w, h) in [(128usize, 128usize), (192, 128)] { round_trips(w, h, &[DC_PRED as u8], fctx); } @@ -38479,7 +38479,7 @@ mod tests { /// decoder round adds, not just `DC_PRED`. #[test] fn every_intra_mode_round_trips_bit_exact_against_the_encoder_reconstruction() { - let fctx = &crate::decode::FrameCtx::new(); + 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) for (w, h) in [(128usize, 128usize), (192, 128)] { round_trips(w, h, &crate::intra::KEY_FRAME_MODES, fctx); } @@ -38490,7 +38490,7 @@ mod tests { /// this decoder round adds. #[test] fn odd_sizes_round_trip_bit_exact_against_the_encoder_reconstruction() { - let fctx = &crate::decode::FrameCtx::new(); + let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: encodes, so the decode context takes this process's superblock size for (w, h) in [(854usize, 480usize), (216, 96)] { round_trips(w, h, &crate::intra::KEY_FRAME_MODES, fctx); } @@ -38504,7 +38504,7 @@ mod tests { /// bit, `partition_w8` leaves). #[test] fn leaf8_straddle_sizes_round_trip_bit_exact_against_the_encoder_reconstruction() { - let fctx = &crate::decode::FrameCtx::new(); + 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) for (w, h) in [(40usize, 32usize), (640, 360)] { round_trips(w, h, &crate::intra::KEY_FRAME_MODES, fctx); } @@ -38800,7 +38800,7 @@ mod tests { /// crate's own writer and reader could otherwise share. #[test] fn ffmpeg_and_this_decoder_agree_on_a_key_frame() { - let fctx = &crate::decode::FrameCtx::new(); + 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) if !have_ffmpeg() { eprintln!("SKIP ffmpeg_and_this_decoder_agree_on_a_key_frame: no ffmpeg"); return; @@ -38847,7 +38847,7 @@ mod tests { /// between the palette colours and the colour-index maps). #[test] fn a_filter_intra_key_frame_decodes_pixel_exact_through_ffmpeg() { - let fctx = &crate::decode::FrameCtx::new(); + 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) if !crate::encode::filter_intra_on() { eprintln!("SKIP a_filter_intra_key_frame...: EC_AV1_FILTER_INTRA=0"); return; @@ -38917,7 +38917,7 @@ mod tests { /// wire). #[test] fn a_key_frames_tile_needs_the_headers_own_tx_select_bit() { - let fctx = &crate::decode::FrameCtx::new(); + let fctx = &crate::decode::FrameCtx::for_encoder(); // lane-b128: encodes, so the decode context takes this process's superblock size use crate::encode::encode_key_frame_with_ctx; let (width, height) = (64usize, 64usize); let picture = round_trip_test_card(width, height); @@ -39117,7 +39117,7 @@ mod tests { #[test] fn a_gop_round_trips_bit_exact_against_the_encoder_reconstruction() { - let fctx = &crate::decode::FrameCtx::new(); + 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) gop_round_trips(128, 64, fctx); } @@ -39126,7 +39126,7 @@ mod tests { /// split path is exercised too. #[test] fn an_odd_size_gop_round_trips_bit_exact_against_the_encoder_reconstruction() { - let fctx = &crate::decode::FrameCtx::new(); + 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) gop_round_trips(216, 96, fctx); } @@ -39356,7 +39356,7 @@ mod tests { #[test] fn ffmpeg_and_this_decoder_agree_on_a_gop() { - let fctx = &crate::decode::FrameCtx::new(); + 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) if !have_ffmpeg() { eprintln!("SKIP ffmpeg_and_this_decoder_agree_on_a_gop: no ffmpeg"); return; diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index bc745700..ae6a4284 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -722,6 +722,17 @@ pub fn take_b64_root_hits() -> usize { B64_HITS.swap(0, std::sync::atomic::Ordering::Relaxed) } +/// Whether the 128 superblock root offers its `PARTITION_NONE` candidate at +/// all ([`search_root_128`]). On by default; `EC_AV1_B128=0` turns it off, +/// which is the attribution arm for a 128-superblock stream: it separates +/// what the SIZE costs from what the 128x128 BLOCK buys. +fn b128_root() -> bool { + static ENV: std::sync::LazyLock = std::sync::LazyLock::new(|| { + crate::envflags::var("EC_AV1_B128").ok().is_none_or(|v| v != "0") + }); + *ENV +} + /// How many 128x128 `PARTITION_NONE` roots the search took since the last /// [`take_b128_none_hits`] (class `gate-blind-to-feature`): a flat BD result /// is only attributable once the fire count is known. @@ -11638,7 +11649,7 @@ pub(crate) fn encode_inter_frame( // 128x128 candidate is weighed. let mark128 = blocks.len(); let mut root_cost = 0.0f64; - let root128 = sb128_search + let root128 = (sb128_search && b128_root() && cells.len() == 4) .then(|| search_root_128( &mut luma, &mut chroma,