forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-sb128fix' (d14eda95): the decoder's frame context is seeded from the stream only; encoder contexts come from FrameCtx::for_encoder (the sb128 merge had raced real 128-superblock decode gates against the encoder witness)

Browse files at this commit

bbeb761be6308b1ac6dbde8b5abcab6bf4dd4c37Ahmet Kaan GümüşParent: ad81365d1b410e
crates/ec-av1/src/decode.rsmodified+20 -11
@@ -158,12 +158,11 @@ impl FrameCtx {
158158 /// predecessor was born with.
159159 pub(crate) fn new() -> Self {
160160 Self {
161- // lane-sb128: an ENCODER context starts at the sequence size
162- // this process encodes (`crate::encode::sb128_on`) so the mode
163- // search's own `Reach` and the filter search's internal decodes
164- // agree with the tile writer; every real decode overwrites it
165- // from the parsed sequence header (`set_sb128`, stream.rs).
166- sb128_flag: std::cell::Cell::new(crate::encode::sb128_on()),
161+ // A DECODER context is seeded from the stream alone: every real
162+ // decode overwrites this from the parsed sequence header
163+ // (`set_sb128`, stream.rs). The encoder's own contexts start at
164+ // the size this process encodes -- see [`FrameCtx::for_encoder`].
165+ sb128_flag: std::cell::Cell::new(false),
167166 lossless_flag: std::cell::Cell::new(false),
168167 cdef_bits: std::cell::Cell::new(0),
169168 bit_depth: std::cell::Cell::new(8),
@@ -208,11 +207,7 @@ impl FrameCtx {
208207 inter_last_mc: std::cell::Cell::new(None),
209208 enable_edge_filter: std::cell::Cell::new(false),
210209 last_frame_wide_margin: std::cell::RefCell::new(None),
211- reach_sb_px: std::cell::Cell::new(if crate::encode::sb128_on() {
212- 128
213- } else {
214- crate::encode::SUPERBLOCK
215- }),
210+ reach_sb_px: std::cell::Cell::new(crate::encode::SUPERBLOCK),
216211 grain_bit_depth: std::cell::Cell::new(8),
217212 recon_ops: std::cell::RefCell::new(Vec::new()),
218213 recon_spare: std::cell::RefCell::new(Vec::new()),
@@ -225,6 +220,20 @@ impl FrameCtx {
225220 wave_mark: std::cell::Cell::new(None),
226221 }
227222 }
223+
224+ /// A context for the ENCODER's own trial decodes: it starts at the
225+ /// superblock size this process encodes (`crate::encode::sb128_on`) so
226+ /// the mode search's `Reach` and the filter search's internal decodes
227+ /// agree with the tile writer. A decoder never reads that knob -- doing
228+ /// so coupled every decode to the encoder's process-global and raced the
229+ /// 128-superblock decode gates against the encoder witness.
230+ pub(crate) fn for_encoder() -> Self {
231+ let ctx = Self::new();
232+ let on = crate::encode::sb128_on();
233+ ctx.sb128_flag.set(on);
234+ ctx.reach_sb_px.set(if on { 128 } else { crate::encode::SUPERBLOCK });
235+ ctx
236+ }
228237 }
229238
230239 /// `LocalKey::with` for a plain value: lets every former `STATIC.with(|c| ..)`
crates/ec-av1/src/encode.rsmodified+64 -63
@@ -4667,18 +4667,19 @@ fn cfl_on() -> bool {
46674667 // the same env-flag shape `EC_AV1_FILTER_INTRA` uses. NOT an `EncoderConfig`
46684668 // field: that struct is built by 90 literal sites in this workspace.
46694669
4670-/// Whether this process's sequences code 128x128 superblocks. Read through
4671-/// a process-global (not a thread-local) because the tile writers run on
4670+/// Whether this process's sequences code 128x128 superblocks. An ENCODER
4671+/// knob (like `speed::SPEED`), never read by a decode: read through a
4672+/// process-global (not a thread-local) because the tile writers run on
46724673 /// worker threads; `2` is "the environment has not been read yet".
4673-static SB128: std::sync::atomic::AtomicU8 = std::sync::atomic::AtomicU8::new(2);
4674+static ENC_SB128: std::sync::atomic::AtomicU8 = std::sync::atomic::AtomicU8::new(2);
46744675
46754676 /// Whether this process's sequences code 128x128 superblocks.
46764677 pub(crate) fn sb128_on() -> bool {
46774678 use std::sync::atomic::Ordering::Relaxed;
4678- match SB128.load(Relaxed) {
4679+ match ENC_SB128.load(Relaxed) {
46794680 2 => {
46804681 let on = crate::envflags::var("EC_AV1_SB128").ok().is_some_and(|v| v != "0");
4681- SB128.store(u8::from(on), Relaxed);
4682+ ENC_SB128.store(u8::from(on), Relaxed);
46824683 on
46834684 }
46844685 v => v == 1,
@@ -4690,7 +4691,7 @@ pub(crate) fn sb128_on() -> bool {
46904691 /// exactly like the speed-preset gates.
46914692 #[cfg(test)]
46924693 pub(crate) fn force_sb128(on: bool) {
4693- SB128.store(u8::from(on), std::sync::atomic::Ordering::Relaxed);
4694+ ENC_SB128.store(u8::from(on), std::sync::atomic::Ordering::Relaxed);
46944695 }
46954696
46964697 /// The luma loop-restoration unit size this sequence codes: a 128 superblock
@@ -6456,7 +6457,7 @@ fn clip_planes_to_tile(
64566457 /// Returns an error under the same conditions
64576458 /// [`encode_key_frame_with_modes`] does.
64586459 pub fn encode_key_frame(picture: &Picture, base_q_idx: u8, deadzone: f64) -> Result<Encoded> {
6459- encode_key_frame_with_ctx(picture, base_q_idx, deadzone, &crate::decode::FrameCtx::new())
6460+ encode_key_frame_with_ctx(picture, base_q_idx, deadzone, &crate::decode::FrameCtx::for_encoder())
64606461 }
64616462
64626463 /// [`encode_key_frame`] with the per-block intra modes given rather than
@@ -6476,7 +6477,7 @@ pub fn encode_key_frame_with_modes(
64766477 base_q_idx,
64776478 deadzone,
64786479 modes,
6479- &crate::decode::FrameCtx::new(),
6480+ &crate::decode::FrameCtx::for_encoder(),
64806481 )
64816482 }
64826483
@@ -6498,7 +6499,7 @@ pub fn encode_sequence(
64986499 base_q_idx: u8,
64996500 deadzone: f64,
65006501 ) -> Result<EncodedSequence> {
6501- encode_sequence_with_ctx(pictures, base_q_idx, deadzone, &crate::decode::FrameCtx::new())
6502+ encode_sequence_with_ctx(pictures, base_q_idx, deadzone, &crate::decode::FrameCtx::for_encoder())
65026503 }
65036504
65046505 pub(crate) fn encode_key_frame_with_ctx(picture: &Picture, base_q_idx: u8, deadzone: f64, fctx: &crate::decode::FrameCtx) -> Result<Encoded> {
@@ -11171,7 +11172,7 @@ mod tests {
1117111172 /// (the horizontal shapes, which those partitions never produce).
1117211173 #[test]
1117311174 fn every_rect_shape_reaches_what_libaom_says_over_the_whole_superblock() {
11174- let fctx = &crate::decode::FrameCtx::new();
11175+ let fctx = &crate::decode::FrameCtx::for_encoder();
1117511176 // (bw, bh, has_tr len, has_tr byte sum, has_bl len, has_bl byte sum).
1117611177 const SHAPES: [(usize, usize, usize, u32, usize, u32); 14] = [
1117711178 (4, 8, 64, 9280, 64, 550),
@@ -11345,7 +11346,7 @@ mod tests {
1134511346 #[test]
1134611347 fn the_filter_search_picks_real_filters() {
1134711348 let _knobs = crate::speed::knob_read();
11348- let fctx = &crate::decode::FrameCtx::new();
11349+ let fctx = &crate::decode::FrameCtx::for_encoder();
1134911350 let pictures: Vec<_> = (0..3).map(|i| panned_test_card(128, 128, i * 3)).collect();
1135011351 let encoded = encode_sequence_with_ctx(&pictures, 120, 0.5, fctx).unwrap();
1135111352 let fired = encoded
@@ -11426,7 +11427,7 @@ mod tests {
1142611427 #[test]
1142711428 fn a_smooth_gradient_key_frame_codes_whole_superblocks_and_decodes_exactly() {
1142811429 let _knobs = crate::speed::knob_read();
11429- let fctx = &crate::decode::FrameCtx::new();
11430+ let fctx = &crate::decode::FrameCtx::for_encoder();
1143011431 // 4 x 3 superblocks, all of them wholly inside the frame.
1143111432 let (width, height) = (256usize, 192usize);
1143211433 let mut picture = Picture::grey(width, height);
@@ -11484,7 +11485,7 @@ mod tests {
1148411485 #[test]
1148511486 fn ffmpeg_decodes_exactly_what_the_encoder_reconstructed() {
1148611487 let _knobs = crate::speed::knob_read();
11487- let fctx = &crate::decode::FrameCtx::new();
11488+ let fctx = &crate::decode::FrameCtx::for_encoder();
1148811489 if !have_ffmpeg() {
1148911490 eprintln!("SKIP ffmpeg_decodes_exactly_what_the_encoder_reconstructed: no ffmpeg");
1149011491 return;
@@ -11566,7 +11567,7 @@ mod tests {
1156611567 #[test]
1156711568 fn a_screen_content_picture_codes_palette_blocks_ffmpeg_decodes_exactly() {
1156811569 let _knobs = crate::speed::knob_read();
11569- let fctx = &crate::decode::FrameCtx::new();
11570+ let fctx = &crate::decode::FrameCtx::for_encoder();
1157011571 let (width, height) = (192usize, 96usize);
1157111572 let _ = crate::tile::take_palette_hits();
1157211573 let picture = screen_card(width, height);
@@ -11677,7 +11678,7 @@ mod tests {
1167711678 #[ignore = "needs the real-library manifest and ffmpeg"]
1167811679 fn probe_intrabc_key_frame() {
1167911680 let _knobs = crate::speed::knob_write();
11680- let fctx = &crate::decode::FrameCtx::new();
11681+ let fctx = &crate::decode::FrameCtx::for_encoder();
1168111682 let fixtures = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
1168211683 .join("../../fixtures");
1168311684 let Ok(manifest) = std::fs::read_to_string(fixtures.join("real-library-manifest.tsv")) else {
@@ -11727,7 +11728,7 @@ mod tests {
1172711728 #[test]
1172811729 fn a_repeated_pattern_key_frame_codes_intrabc_blocks_ffmpeg_decodes_exactly() {
1172911730 let _knobs = crate::speed::knob_write();
11730- let fctx = &crate::decode::FrameCtx::new();
11731+ let fctx = &crate::decode::FrameCtx::for_encoder();
1173111732 // Wide enough for the wavefront rule (`INTRABC_DELAY_SB64` = 4
1173211733 // superblocks of 64) and tall enough for a source superblock row
1173311734 // above the blocks that copy from it.
@@ -11786,7 +11787,7 @@ mod tests {
1178611787 #[test]
1178711788 fn a_nearestmv_block_with_one_nonzero_coefficient_decodes_clean() {
1178811789 let _knobs = crate::speed::knob_write();
11789- let fctx = &crate::decode::FrameCtx::new();
11790+ let fctx = &crate::decode::FrameCtx::for_encoder();
1179011791 if !have_ffmpeg() {
1179111792 eprintln!(
1179211793 "SKIP a_nearestmv_block_with_one_nonzero_coefficient_decodes_clean: no ffmpeg"
@@ -11921,7 +11922,7 @@ mod tests {
1192111922 #[test]
1192211923 fn the_final_filter_replay_matches_the_capture_decode_at_odd_sizes() {
1192311924 let _knobs = crate::speed::knob_write();
11924- let fctx = &crate::decode::FrameCtx::new();
11925+ let fctx = &crate::decode::FrameCtx::for_encoder();
1192511926 crate::decode::set_verify_final_replay(true);
1192611927 for &(width, height) in
1192711928 &[(64usize, 56usize), (216, 96), (192, 120), (640, 352), (1280, 720)]
@@ -11950,7 +11951,7 @@ mod tests {
1195011951 #[test]
1195111952 fn a_frame_round_trips_at_its_own_size() {
1195211953 let _knobs = crate::speed::knob_read();
11953- let fctx = &crate::decode::FrameCtx::new();
11954+ let fctx = &crate::decode::FrameCtx::for_encoder();
1195411955 if !have_ffmpeg() {
1195511956 eprintln!("SKIP a_frame_round_trips_at_its_own_size: no ffmpeg");
1195611957 return;
@@ -12017,7 +12018,7 @@ mod tests {
1201712018 #[test]
1201812019 fn an_854x480_picture_round_trips_through_its_padding() {
1201912020 let _knobs = crate::speed::knob_read();
12020- let fctx = &crate::decode::FrameCtx::new();
12021+ let fctx = &crate::decode::FrameCtx::for_encoder();
1202112022 if !have_ffmpeg() {
1202212023 return;
1202312024 }
@@ -12048,7 +12049,7 @@ mod tests {
1204812049 /// (`has_tr_vert_8x8` bit 16 = 0, ordinary `has_tr_8x8` bit 16 = 1).
1204912050 #[test]
1205012051 fn of_tu_follows_the_block_row_including_under_vert_ab() {
12051- let fctx = &crate::decode::FrameCtx::new();
12052+ let fctx = &crate::decode::FrameCtx::for_encoder();
1205212053 // The 8x8 square at superblock row 1, column 0, and the TX4 unit in
1205312054 // its top-right corner (`col_off = 4`, `row_off = 0`): that unit's
1205412055 // above-right answer is the BLOCK's, which is the whole reason a unit
@@ -12083,7 +12084,7 @@ mod tests {
1208312084 /// wrong for one block size while looking plausible for the other.
1208412085 #[test]
1208512086 fn reach_matches_libaom_has_top_right_and_has_bottom_left() {
12086- let fctx = &crate::decode::FrameCtx::new();
12087+ let fctx = &crate::decode::FrameCtx::for_encoder();
1208712088 // Transcribed from has_top_right/has_bottom_left's row_off==0,
1208812089 // col_off==0 (whole-transform) path, with MAX_MIB_SIZE_LOG2 = 5 (a
1208912090 // 128px reference grid) pinned as libaom pins it, independent of the
@@ -12228,7 +12229,7 @@ mod tests {
1222812229
1222912230 #[test]
1223012231 fn vert_ab_partition_flips_below_left_for_the_top_right_8x8() {
12231- let fctx = &crate::decode::FrameCtx::new();
12232+ let fctx = &crate::decode::FrameCtx::for_encoder();
1223212233 let (width, height) = (SUPERBLOCK * 3, SUPERBLOCK * 3);
1223312234 // Interior superblock, so neither the frame edge nor the col == 0 /
1223412235 // last-row early returns answer instead of the table.
@@ -12263,7 +12264,7 @@ mod tests {
1226312264 #[test]
1226412265 fn odd_dimensions_are_refused() {
1226512266 let _knobs = crate::speed::knob_read();
12266- let fctx = &crate::decode::FrameCtx::new();
12267+ let fctx = &crate::decode::FrameCtx::for_encoder();
1226712268 for &(width, height) in &[(1921usize, 1080usize), (1920, 1081), (63, 63)] {
1226812269 let picture = Picture::grey(width, height);
1226912270 let err = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx)
@@ -12282,7 +12283,7 @@ mod tests {
1228212283 #[test]
1228312284 fn sequence_round_trips_at_a_non_multiple_size() {
1228412285 let _knobs = crate::speed::knob_read();
12285- let fctx = &crate::decode::FrameCtx::new();
12286+ let fctx = &crate::decode::FrameCtx::for_encoder();
1228612287 if !have_ffmpeg() {
1228712288 eprintln!("SKIP sequence_round_trips_at_a_non_multiple_size: no ffmpeg");
1228812289 return;
@@ -12326,7 +12327,7 @@ mod tests {
1232612327 #[test]
1232712328 fn a_sequence_round_trips_at_the_exactly_half_straddle_size() {
1232812329 let _knobs = crate::speed::knob_read();
12329- let fctx = &crate::decode::FrameCtx::new();
12330+ let fctx = &crate::decode::FrameCtx::for_encoder();
1233012331 if !have_ffmpeg() {
1233112332 eprintln!("SKIP a_sequence_round_trips_at_the_exactly_half_straddle_size: no ffmpeg");
1233212333 return;
@@ -12372,7 +12373,7 @@ mod tests {
1237212373 #[test]
1237312374 fn key_frame_and_inter_frame_both_encode_at_half_straddle_size() {
1237412375 let _knobs = crate::speed::knob_read();
12375- let fctx = &crate::decode::FrameCtx::new();
12376+ let fctx = &crate::decode::FrameCtx::for_encoder();
1237612377 let (width, height) = (640usize, 360usize);
1237712378 let picture = Picture::grey(width, height);
1237812379 encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).expect("key frame now codes the mod-32==8 straddle");
@@ -12392,7 +12393,7 @@ mod tests {
1239212393 #[test]
1239312394 fn a_640x360_half_straddle_round_trips_through_ffmpeg_across_three_frames() {
1239412395 let _knobs = crate::speed::knob_read();
12395- let fctx = &crate::decode::FrameCtx::new();
12396+ let fctx = &crate::decode::FrameCtx::for_encoder();
1239612397 if !have_ffmpeg() {
1239712398 eprintln!(
1239812399 "SKIP a_640x360_half_straddle_round_trips_through_ffmpeg_across_three_frames: \
@@ -12418,7 +12419,7 @@ mod tests {
1241812419 #[test]
1241912420 fn a_640x360_half_straddle_sequence_round_trips_through_ffmpeg() {
1242012421 let _knobs = crate::speed::knob_read();
12421- let fctx = &crate::decode::FrameCtx::new();
12422+ let fctx = &crate::decode::FrameCtx::for_encoder();
1242212423 if !have_ffmpeg() {
1242312424 eprintln!(
1242412425 "SKIP a_640x360_half_straddle_sequence_round_trips_through_ffmpeg: no ffmpeg"
@@ -12478,7 +12479,7 @@ mod tests {
1247812479 #[ignore = "a sweep, not a gate"]
1247912480 fn probe_lambda() {
1248012481 let _knobs = crate::speed::knob_read();
12481- let fctx = &crate::decode::FrameCtx::new();
12482+ let fctx = &crate::decode::FrameCtx::for_encoder();
1248212483 let mut pictures = vec![
1248312484 ("test card".to_string(), test_card(160, 96)),
1248412485 ("stripes".to_string(), stripes(160, 96, true)),
@@ -12510,7 +12511,7 @@ mod tests {
1251012511 #[ignore = "a sweep, not a gate"]
1251112512 fn probe_ladder() {
1251212513 let _knobs = crate::speed::knob_read();
12513- let fctx = &crate::decode::FrameCtx::new();
12514+ let fctx = &crate::decode::FrameCtx::for_encoder();
1251412515 for (name, picture) in sweep_pictures() {
1251512516 let all = ladder(&picture, &KEY_FRAME_MODES, fctx);
1251612517 let points = all
@@ -12529,7 +12530,7 @@ mod tests {
1252912530 #[ignore = "a sweep, not a gate"]
1253012531 fn probe_split() {
1253112532 let _knobs = crate::speed::knob_read();
12532- let fctx = &crate::decode::FrameCtx::new();
12533+ let fctx = &crate::decode::FrameCtx::for_encoder();
1253312534 for (name, picture) in sweep_pictures() {
1253412535 let ladder = |split: bool| {
1253512536 let mut points: Vec<(f64, f64)> = [110u8, 90, 70]
@@ -12611,7 +12612,7 @@ mod tests {
1261112612 #[test]
1261212613 fn every_mode_decodes_to_what_the_encoder_predicted() {
1261312614 let _knobs = crate::speed::knob_write();
12614- let fctx = &crate::decode::FrameCtx::new();
12615+ let fctx = &crate::decode::FrameCtx::for_encoder();
1261512616 if !have_ffmpeg() {
1261612617 eprintln!("SKIP every_mode_decodes_to_what_the_encoder_predicted: no ffmpeg");
1261712618 return;
@@ -12655,7 +12656,7 @@ mod tests {
1265512656 #[test]
1265612657 fn the_search_picks_the_direction_the_picture_runs() {
1265712658 let _knobs = crate::speed::knob_write();
12658- let fctx = &crate::decode::FrameCtx::new();
12659+ let fctx = &crate::decode::FrameCtx::for_encoder();
1265912660 // Same confound as [`every_mode_decodes_to_what_the_encoder_predicted`]:
1266012661 // a filter-intra block is coded `DC_PRED` whatever mode the arm
1266112662 // offers, and these stripes are SCREEN content, where the filter arm
@@ -12763,7 +12764,7 @@ mod tests {
1276312764 #[test]
1276412765 fn the_search_beats_dc_alone() {
1276512766 let _knobs = crate::speed::knob_read();
12766- let fctx = &crate::decode::FrameCtx::new();
12767+ let fctx = &crate::decode::FrameCtx::for_encoder();
1276712768 for (name, picture, want) in [
1276812769 ("test card", test_card(160, 96), -0.05),
1276912770 ("stripes", stripes(160, 96, true), -0.40),
@@ -12806,7 +12807,7 @@ mod tests {
1280612807 #[ignore = "a sweep, not a gate"]
1280712808 fn probe_directional() {
1280812809 let _knobs = crate::speed::knob_write();
12809- let fctx = &crate::decode::FrameCtx::new();
12810+ let fctx = &crate::decode::FrameCtx::for_encoder();
1281012811 for (name, picture) in sweep_pictures() {
1281112812 let dc = ladder(&picture, &[DC_PRED], fctx);
1281212813 let flat = ladder(&picture, &NON_DIRECTIONAL, fctx);
@@ -12881,7 +12882,7 @@ mod tests {
1288112882 #[test]
1288212883 fn the_search_picks_the_diagonal_the_picture_runs() {
1288312884 let _knobs = crate::speed::knob_write();
12884- let fctx = &crate::decode::FrameCtx::new();
12885+ let fctx = &crate::decode::FrameCtx::for_encoder();
1288512886 for (down_right, want) in [(true, D135_PRED), (false, D45_PRED)] {
1288612887 let picture = diagonal(160, 96, down_right);
1288712888 let (mode, count, blocks) = favourite_mode(&picture, fctx);
@@ -12901,7 +12902,7 @@ mod tests {
1290112902 #[test]
1290212903 fn the_diagonals_beat_the_modes_that_read_no_further() {
1290312904 let _knobs = crate::speed::knob_read();
12904- let fctx = &crate::decode::FrameCtx::new();
12905+ let fctx = &crate::decode::FrameCtx::for_encoder();
1290512906 for (name, picture, want) in [
1290612907 ("down-right", diagonal(160, 96, true), -0.20),
1290712908 ("down-left", diagonal(160, 96, false), -0.20),
@@ -12925,7 +12926,7 @@ mod tests {
1292512926 #[test]
1292612927 fn a_mode_the_encoder_cannot_predict_is_refused() {
1292712928 let _knobs = crate::speed::knob_read();
12928- let fctx = &crate::decode::FrameCtx::new();
12929+ let fctx = &crate::decode::FrameCtx::for_encoder();
1292912930 let picture = test_card(64, 64);
1293012931 let message = encode_key_frame_with_modes_with_ctx(&picture, 100, 0.5, &[13], fctx)
1293112932 .unwrap_err()
@@ -12945,7 +12946,7 @@ mod tests {
1294512946 #[test]
1294612947 fn the_encoded_picture_is_the_one_that_went_in() {
1294712948 let _knobs = crate::speed::knob_read();
12948- let fctx = &crate::decode::FrameCtx::new();
12949+ let fctx = &crate::decode::FrameCtx::for_encoder();
1294912950 let picture = test_card(160, 96);
1295012951 let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();
1295112952 let luma = psnr(&encoded.reconstruction.y, &picture.y);
@@ -12968,7 +12969,7 @@ mod tests {
1296812969 #[test]
1296912970 fn fidelity_and_rate_move_with_the_quantizer() {
1297012971 let _knobs = crate::speed::knob_read();
12971- let fctx = &crate::decode::FrameCtx::new();
12972+ let fctx = &crate::decode::FrameCtx::for_encoder();
1297212973 let picture = test_card(128, 128);
1297312974 let mut previous: Option<(usize, f64)> = None;
1297412975 for &q in &[70u8, 90, 110] {
@@ -13029,7 +13030,7 @@ mod tests {
1302913030 #[test]
1303013031 fn a_flat_picture_costs_almost_nothing() {
1303113032 let _knobs = crate::speed::knob_read();
13032- let fctx = &crate::decode::FrameCtx::new();
13033+ let fctx = &crate::decode::FrameCtx::for_encoder();
1303313034 let mut picture = Picture::grey(128, 128);
1303413035 picture.y.fill(97);
1303513036 let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();
@@ -13066,7 +13067,7 @@ mod tests {
1306613067 #[test]
1306713068 fn a_picture_off_the_block_grid_encodes_and_a_malformed_one_is_refused() {
1306813069 let _knobs = crate::speed::knob_read();
13069- let fctx = &crate::decode::FrameCtx::new();
13070+ let fctx = &crate::decode::FrameCtx::for_encoder();
1307013071 encode_key_frame_with_ctx(&Picture::grey(40, 40), 100, 0.5, fctx)
1307113072 .expect("40x40 cuts a 16x16 leaf on both axes, which is an inferred split");
1307213073 encode_key_frame_with_ctx(&Picture::grey(36, 40), 100, 0.5, fctx)
@@ -13150,7 +13151,7 @@ mod tests {
1315013151 #[test]
1315113152 fn a_single_axis_straddle_round_trips_through_ffmpeg() {
1315213153 let _knobs = crate::speed::knob_read();
13153- let fctx = &crate::decode::FrameCtx::new();
13154+ let fctx = &crate::decode::FrameCtx::for_encoder();
1315413155 if !have_ffmpeg() {
1315513156 eprintln!("SKIP a_single_axis_straddle_round_trips_through_ffmpeg: no ffmpeg");
1315613157 return;
@@ -13180,7 +13181,7 @@ mod tests {
1318013181 #[test]
1318113182 fn a_frame_of_real_video_decodes_to_what_the_encoder_reconstructed() {
1318213183 let _knobs = crate::speed::knob_read();
13183- let fctx = &crate::decode::FrameCtx::new();
13184+ let fctx = &crate::decode::FrameCtx::for_encoder();
1318413185 let Ok(clip) = std::env::var("EC_AV1_CLIP") else {
1318513186 eprintln!(
1318613187 "SKIP a_frame_of_real_video_decodes_to_what_the_encoder_reconstructed: \
@@ -13312,7 +13313,7 @@ mod tests {
1331213313 #[test]
1331313314 fn every_frame_of_a_sequence_decodes_to_what_the_encoder_reconstructed() {
1331413315 let _knobs = crate::speed::knob_read();
13315- let fctx = &crate::decode::FrameCtx::new();
13316+ let fctx = &crate::decode::FrameCtx::for_encoder();
1331613317 if !have_ffmpeg() {
1331713318 eprintln!(
1331813319 "SKIP every_frame_of_a_sequence_decodes_to_what_the_encoder_reconstructed: no ffmpeg"
@@ -13354,7 +13355,7 @@ mod tests {
1335413355 #[test]
1335513356 fn every_frame_of_a_sequence_decodes_through_our_own_decoder() {
1335613357 let _knobs = crate::speed::knob_read();
13357- let fctx = &crate::decode::FrameCtx::new();
13358+ let fctx = &crate::decode::FrameCtx::for_encoder();
1335813359 // 256x128, not the 128x64 this started at: once a leaf could search
1335913360 // its second reference (lane-av1comp4) the small card's every
1336013361 // eligible block went to a compound winner, which commits its flat
@@ -13420,7 +13421,7 @@ mod tests {
1342013421 #[test]
1342113422 fn predicted_coeff_bits_track_the_tile_the_writer_wrote() {
1342213423 let _knobs = crate::speed::knob_read();
13423- let fctx = &crate::decode::FrameCtx::new();
13424+ let fctx = &crate::decode::FrameCtx::for_encoder();
1342413425 let (width, height) = (256usize, 128usize);
1342513426 let pictures: Vec<Picture> = (0..5)
1342613427 .map(|i| panned_test_card(width, height, i * 2))
@@ -13525,7 +13526,7 @@ mod tests {
1352513526 #[test]
1352613527 fn pricer_error_census_by_block_class() {
1352713528 let _knobs = crate::speed::knob_read();
13528- let fctx = &crate::decode::FrameCtx::new();
13529+ let fctx = &crate::decode::FrameCtx::for_encoder();
1352913530 let (width, height) = (256usize, 128usize);
1353013531 let pictures: Vec<Picture> = (0..5)
1353113532 .map(|i| panned_test_card(width, height, i * 2))
@@ -13598,7 +13599,7 @@ mod tests {
1359813599 assert!(!clips.is_empty(), "no source clip available");
1359913600 let (width, height, frames) = (640usize, 384usize, 6usize);
1360013601 for (name, path) in &clips {
13601- let fctx = &crate::decode::FrameCtx::new();
13602+ let fctx = &crate::decode::FrameCtx::for_encoder();
1360213603 let source = clip_frames(path.to_str().unwrap(), "0", width, height, frames);
1360313604 SCREEN_FRAMES.iter().for_each(|c| {
1360413605 c.store(0, std::sync::atomic::Ordering::Relaxed);
@@ -13644,7 +13645,7 @@ mod tests {
1364413645 #[test]
1364513646 fn low_motion_makes_an_inter_frame_smaller_than_the_key_frame() {
1364613647 let _knobs = crate::speed::knob_read();
13647- let fctx = &crate::decode::FrameCtx::new();
13648+ let fctx = &crate::decode::FrameCtx::for_encoder();
1364813649 let (width, height) = (256usize, 128usize);
1364913650 let pictures: Vec<Picture> = (0..5)
1365013651 .map(|i| panned_test_card(width, height, i * 2))
@@ -13682,7 +13683,7 @@ mod tests {
1368213683 #[ignore = "a perf probe, not a gate"]
1368313684 fn stage_timing_breakdown() {
1368413685 let _knobs = crate::speed::knob_read();
13685- let fctx = &crate::decode::FrameCtx::new();
13686+ let fctx = &crate::decode::FrameCtx::for_encoder();
1368613687 use std::time::Instant;
1368713688
1368813689 for &(width, height) in &[(1920usize, 1080usize), (3840, 2160)] {
@@ -13805,7 +13806,7 @@ mod tests {
1380513806 #[ignore = "a perf probe, not a gate"]
1380613807 fn stage_timing_breakdown_inter() {
1380713808 let _knobs = crate::speed::knob_read();
13808- let fctx = &crate::decode::FrameCtx::new();
13809+ let fctx = &crate::decode::FrameCtx::for_encoder();
1380913810 use std::time::Instant;
1381013811
1381113812 let (width, height) = (1280usize, 720);
@@ -13854,7 +13855,7 @@ mod tests {
1385413855 #[ignore = "needs real clips and ffmpeg; prints numbers for the lane report to judge"]
1385513856 fn prune_k_quality_sweep() {
1385613857 let _knobs = crate::speed::knob_read();
13857- let fctx = &crate::decode::FrameCtx::new();
13858+ let fctx = &crate::decode::FrameCtx::for_encoder();
1385813859 if !have_ffmpeg() {
1385913860 eprintln!("SKIP prune_k_quality_sweep: no ffmpeg");
1386013861 return;
@@ -13955,7 +13956,7 @@ mod tests {
1395513956 #[ignore = "needs real clips and ffmpeg; prints numbers for the lane report to judge"]
1395613957 fn prune_k_quality_sweep_inter() {
1395713958 let _knobs = crate::speed::knob_read();
13958- let fctx = &crate::decode::FrameCtx::new();
13959+ let fctx = &crate::decode::FrameCtx::for_encoder();
1395913960 if !have_ffmpeg() {
1396013961 eprintln!("SKIP prune_k_quality_sweep_inter: no ffmpeg");
1396113962 return;
@@ -14085,7 +14086,7 @@ mod tests {
1408514086 #[test]
1408614087 fn real_clip_encodes_within_its_quality_and_size_budget() {
1408714088 let _knobs = crate::speed::knob_read();
14088- let fctx = &crate::decode::FrameCtx::new();
14089+ let fctx = &crate::decode::FrameCtx::for_encoder();
1408914090 if !have_ffmpeg() {
1409014091 eprintln!("SKIP real_clip_encodes_within_its_quality_and_size_budget: no ffmpeg");
1409114092 return;
@@ -14147,7 +14148,7 @@ mod tests {
1414714148 #[test]
1414814149 fn real_clip_encodes_within_its_quality_and_size_budget_at_a_straddle_size() {
1414914150 let _knobs = crate::speed::knob_read();
14150- let fctx = &crate::decode::FrameCtx::new();
14151+ let fctx = &crate::decode::FrameCtx::for_encoder();
1415114152 if !have_ffmpeg() {
1415214153 eprintln!(
1415314154 "SKIP real_clip_encodes_within_its_quality_and_size_budget_at_a_straddle_size: \
@@ -14205,7 +14206,7 @@ mod tests {
1420514206 #[ignore = "a perf probe, not a gate"]
1420614207 fn sequence_bench_sanity() {
1420714208 let _knobs = crate::speed::knob_read();
14208- let fctx = &crate::decode::FrameCtx::new();
14209+ let fctx = &crate::decode::FrameCtx::for_encoder();
1420914210 use std::time::Instant;
1421014211 let (width, height) = (1280usize, 720usize);
1421114212 let pictures: Vec<Picture> = (0..24)
@@ -14229,7 +14230,7 @@ mod tests {
1422914230 #[ignore = "a calibration probe, not a gate"]
1423014231 fn calibration_sweep_base_q_idx() {
1423114232 let _knobs = crate::speed::knob_read();
14232- let fctx = &crate::decode::FrameCtx::new();
14233+ let fctx = &crate::decode::FrameCtx::for_encoder();
1423314234 if !have_ffmpeg() {
1423414235 eprintln!("SKIP calibration_sweep_base_q_idx: no ffmpeg");
1423514236 return;
@@ -15216,7 +15217,7 @@ mod tests {
1521615217 println!("| clip | ours PSNR/bytes per point | BD-rate vs libaom | BD-rate vs rav1e | wall ours:libaom:rav1e |");
1521715218 println!("|---|---|---|---|---|");
1521815219 for (name, path) in &clips {
15219- let fctx = &crate::decode::FrameCtx::new();
15220+ let fctx = &crate::decode::FrameCtx::for_encoder();
1522015221 let source = clip_frames(path.to_str().unwrap(), "0", width, height, frames);
1522115222 let _ = take_partition_hits();
1522215223 let _ = crate::tile::take_palette_hits();
@@ -15849,7 +15850,7 @@ mod tests {
1584915850 println!("| clip | ours PSNR/bytes per point | BD-rate vs libaom | BD-rate vs rav1e | wall ours:libaom:rav1e (noisy) |");
1585015851 println!("|---|---|---|---|---|");
1585115852 for (name, path, seek) in &clips {
15852- let fctx = &crate::decode::FrameCtx::new();
15853+ let fctx = &crate::decode::FrameCtx::for_encoder();
1585315854 if probe_dims(path).is_none() {
1585415855 eprintln!("SKIP {name}: ffprobe gave no size");
1585515856 continue;
@@ -16118,7 +16119,7 @@ mod tests {
1611816119 "the probe's source differs from the gate's at the same window"
1611916120 );
1612016121 let bytes = |src: &[Picture]| {
16121- encode_sequence_with_ctx(src, q, 0.5, &crate::decode::FrameCtx::new())
16122+ encode_sequence_with_ctx(src, q, 0.5, &crate::decode::FrameCtx::for_encoder())
1612216123 .unwrap()
1612316124 .stream
1612416125 };
@@ -16152,7 +16153,7 @@ mod tests {
1615216153 let frames: usize = g("EC_PARITY_FRAMES").parse().unwrap();
1615316154 let q: u8 = g("EC_PARITY_Q").parse().unwrap();
1615416155 let source = clip_frames_vf(&g("EC_PARITY_CLIP"), &g("EC_PARITY_SS"), &g("EC_PARITY_VF"), w, h, frames);
16155- let fctx = &crate::decode::FrameCtx::new();
16156+ let fctx = &crate::decode::FrameCtx::for_encoder();
1615616157 let e = encode_sequence_with_ctx(&source, q, 0.5, fctx).unwrap();
1615716158 let mut hash: u64 = 0xcbf2_9ce4_8422_2325;
1615816159 for &b in &e.stream {
crates/ec-av1/src/encoder.rsmodified+1 -1
@@ -1191,7 +1191,7 @@ impl Av1Encoder {
11911191 reference: None,
11921192 next_index: 0,
11931193 rate_loop: None,
1194- fctx: crate::decode::FrameCtx::new(),
1194+ fctx: crate::decode::FrameCtx::for_encoder(),
11951195 pyramid: None,
11961196 dpb: [const { None }; 8],
11971197 pending: Vec::new(),