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 commit3 changed files +85 -75
- crates/ec-av1/src/decode.rs +20 -11
- crates/ec-av1/src/encode.rs +64 -63
- crates/ec-av1/src/encoder.rs +1 -1
crates/ec-av1/src/decode.rsmodified+20 -11
| @@ -158,12 +158,11 @@ impl FrameCtx { | ||
| 158 | 158 | /// predecessor was born with. |
| 159 | 159 | pub(crate) fn new() -> Self { |
| 160 | 160 | 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), | |
| 167 | 166 | lossless_flag: std::cell::Cell::new(false), |
| 168 | 167 | cdef_bits: std::cell::Cell::new(0), |
| 169 | 168 | bit_depth: std::cell::Cell::new(8), |
| @@ -208,11 +207,7 @@ impl FrameCtx { | ||
| 208 | 207 | inter_last_mc: std::cell::Cell::new(None), |
| 209 | 208 | enable_edge_filter: std::cell::Cell::new(false), |
| 210 | 209 | 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), | |
| 216 | 211 | grain_bit_depth: std::cell::Cell::new(8), |
| 217 | 212 | recon_ops: std::cell::RefCell::new(Vec::new()), |
| 218 | 213 | recon_spare: std::cell::RefCell::new(Vec::new()), |
| @@ -225,6 +220,20 @@ impl FrameCtx { | ||
| 225 | 220 | wave_mark: std::cell::Cell::new(None), |
| 226 | 221 | } |
| 227 | 222 | } |
| 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 | + } | |
| 228 | 237 | } |
| 229 | 238 | |
| 230 | 239 | /// `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 { | ||
| 4667 | 4667 | // the same env-flag shape `EC_AV1_FILTER_INTRA` uses. NOT an `EncoderConfig` |
| 4668 | 4668 | // field: that struct is built by 90 literal sites in this workspace. |
| 4669 | 4669 | |
| 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 | |
| 4672 | 4673 | /// 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); | |
| 4674 | 4675 | |
| 4675 | 4676 | /// Whether this process's sequences code 128x128 superblocks. |
| 4676 | 4677 | pub(crate) fn sb128_on() -> bool { |
| 4677 | 4678 | use std::sync::atomic::Ordering::Relaxed; |
| 4678 | - match SB128.load(Relaxed) { | |
| 4679 | + match ENC_SB128.load(Relaxed) { | |
| 4679 | 4680 | 2 => { |
| 4680 | 4681 | 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); | |
| 4682 | 4683 | on |
| 4683 | 4684 | } |
| 4684 | 4685 | v => v == 1, |
| @@ -4690,7 +4691,7 @@ pub(crate) fn sb128_on() -> bool { | ||
| 4690 | 4691 | /// exactly like the speed-preset gates. |
| 4691 | 4692 | #[cfg(test)] |
| 4692 | 4693 | 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); | |
| 4694 | 4695 | } |
| 4695 | 4696 | |
| 4696 | 4697 | /// The luma loop-restoration unit size this sequence codes: a 128 superblock |
| @@ -6456,7 +6457,7 @@ fn clip_planes_to_tile( | ||
| 6456 | 6457 | /// Returns an error under the same conditions |
| 6457 | 6458 | /// [`encode_key_frame_with_modes`] does. |
| 6458 | 6459 | 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()) | |
| 6460 | 6461 | } |
| 6461 | 6462 | |
| 6462 | 6463 | /// [`encode_key_frame`] with the per-block intra modes given rather than |
| @@ -6476,7 +6477,7 @@ pub fn encode_key_frame_with_modes( | ||
| 6476 | 6477 | base_q_idx, |
| 6477 | 6478 | deadzone, |
| 6478 | 6479 | modes, |
| 6479 | - &crate::decode::FrameCtx::new(), | |
| 6480 | + &crate::decode::FrameCtx::for_encoder(), | |
| 6480 | 6481 | ) |
| 6481 | 6482 | } |
| 6482 | 6483 | |
| @@ -6498,7 +6499,7 @@ pub fn encode_sequence( | ||
| 6498 | 6499 | base_q_idx: u8, |
| 6499 | 6500 | deadzone: f64, |
| 6500 | 6501 | ) -> 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()) | |
| 6502 | 6503 | } |
| 6503 | 6504 | |
| 6504 | 6505 | 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 { | ||
| 11171 | 11172 | /// (the horizontal shapes, which those partitions never produce). |
| 11172 | 11173 | #[test] |
| 11173 | 11174 | 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(); | |
| 11175 | 11176 | // (bw, bh, has_tr len, has_tr byte sum, has_bl len, has_bl byte sum). |
| 11176 | 11177 | const SHAPES: [(usize, usize, usize, u32, usize, u32); 14] = [ |
| 11177 | 11178 | (4, 8, 64, 9280, 64, 550), |
| @@ -11345,7 +11346,7 @@ mod tests { | ||
| 11345 | 11346 | #[test] |
| 11346 | 11347 | fn the_filter_search_picks_real_filters() { |
| 11347 | 11348 | let _knobs = crate::speed::knob_read(); |
| 11348 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 11349 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 11349 | 11350 | let pictures: Vec<_> = (0..3).map(|i| panned_test_card(128, 128, i * 3)).collect(); |
| 11350 | 11351 | let encoded = encode_sequence_with_ctx(&pictures, 120, 0.5, fctx).unwrap(); |
| 11351 | 11352 | let fired = encoded |
| @@ -11426,7 +11427,7 @@ mod tests { | ||
| 11426 | 11427 | #[test] |
| 11427 | 11428 | fn a_smooth_gradient_key_frame_codes_whole_superblocks_and_decodes_exactly() { |
| 11428 | 11429 | let _knobs = crate::speed::knob_read(); |
| 11429 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 11430 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 11430 | 11431 | // 4 x 3 superblocks, all of them wholly inside the frame. |
| 11431 | 11432 | let (width, height) = (256usize, 192usize); |
| 11432 | 11433 | let mut picture = Picture::grey(width, height); |
| @@ -11484,7 +11485,7 @@ mod tests { | ||
| 11484 | 11485 | #[test] |
| 11485 | 11486 | fn ffmpeg_decodes_exactly_what_the_encoder_reconstructed() { |
| 11486 | 11487 | let _knobs = crate::speed::knob_read(); |
| 11487 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 11488 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 11488 | 11489 | if !have_ffmpeg() { |
| 11489 | 11490 | eprintln!("SKIP ffmpeg_decodes_exactly_what_the_encoder_reconstructed: no ffmpeg"); |
| 11490 | 11491 | return; |
| @@ -11566,7 +11567,7 @@ mod tests { | ||
| 11566 | 11567 | #[test] |
| 11567 | 11568 | fn a_screen_content_picture_codes_palette_blocks_ffmpeg_decodes_exactly() { |
| 11568 | 11569 | let _knobs = crate::speed::knob_read(); |
| 11569 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 11570 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 11570 | 11571 | let (width, height) = (192usize, 96usize); |
| 11571 | 11572 | let _ = crate::tile::take_palette_hits(); |
| 11572 | 11573 | let picture = screen_card(width, height); |
| @@ -11677,7 +11678,7 @@ mod tests { | ||
| 11677 | 11678 | #[ignore = "needs the real-library manifest and ffmpeg"] |
| 11678 | 11679 | fn probe_intrabc_key_frame() { |
| 11679 | 11680 | let _knobs = crate::speed::knob_write(); |
| 11680 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 11681 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 11681 | 11682 | let fixtures = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) |
| 11682 | 11683 | .join("../../fixtures"); |
| 11683 | 11684 | let Ok(manifest) = std::fs::read_to_string(fixtures.join("real-library-manifest.tsv")) else { |
| @@ -11727,7 +11728,7 @@ mod tests { | ||
| 11727 | 11728 | #[test] |
| 11728 | 11729 | fn a_repeated_pattern_key_frame_codes_intrabc_blocks_ffmpeg_decodes_exactly() { |
| 11729 | 11730 | let _knobs = crate::speed::knob_write(); |
| 11730 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 11731 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 11731 | 11732 | // Wide enough for the wavefront rule (`INTRABC_DELAY_SB64` = 4 |
| 11732 | 11733 | // superblocks of 64) and tall enough for a source superblock row |
| 11733 | 11734 | // above the blocks that copy from it. |
| @@ -11786,7 +11787,7 @@ mod tests { | ||
| 11786 | 11787 | #[test] |
| 11787 | 11788 | fn a_nearestmv_block_with_one_nonzero_coefficient_decodes_clean() { |
| 11788 | 11789 | let _knobs = crate::speed::knob_write(); |
| 11789 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 11790 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 11790 | 11791 | if !have_ffmpeg() { |
| 11791 | 11792 | eprintln!( |
| 11792 | 11793 | "SKIP a_nearestmv_block_with_one_nonzero_coefficient_decodes_clean: no ffmpeg" |
| @@ -11921,7 +11922,7 @@ mod tests { | ||
| 11921 | 11922 | #[test] |
| 11922 | 11923 | fn the_final_filter_replay_matches_the_capture_decode_at_odd_sizes() { |
| 11923 | 11924 | let _knobs = crate::speed::knob_write(); |
| 11924 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 11925 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 11925 | 11926 | crate::decode::set_verify_final_replay(true); |
| 11926 | 11927 | for &(width, height) in |
| 11927 | 11928 | &[(64usize, 56usize), (216, 96), (192, 120), (640, 352), (1280, 720)] |
| @@ -11950,7 +11951,7 @@ mod tests { | ||
| 11950 | 11951 | #[test] |
| 11951 | 11952 | fn a_frame_round_trips_at_its_own_size() { |
| 11952 | 11953 | let _knobs = crate::speed::knob_read(); |
| 11953 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 11954 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 11954 | 11955 | if !have_ffmpeg() { |
| 11955 | 11956 | eprintln!("SKIP a_frame_round_trips_at_its_own_size: no ffmpeg"); |
| 11956 | 11957 | return; |
| @@ -12017,7 +12018,7 @@ mod tests { | ||
| 12017 | 12018 | #[test] |
| 12018 | 12019 | fn an_854x480_picture_round_trips_through_its_padding() { |
| 12019 | 12020 | let _knobs = crate::speed::knob_read(); |
| 12020 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 12021 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 12021 | 12022 | if !have_ffmpeg() { |
| 12022 | 12023 | return; |
| 12023 | 12024 | } |
| @@ -12048,7 +12049,7 @@ mod tests { | ||
| 12048 | 12049 | /// (`has_tr_vert_8x8` bit 16 = 0, ordinary `has_tr_8x8` bit 16 = 1). |
| 12049 | 12050 | #[test] |
| 12050 | 12051 | 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(); | |
| 12052 | 12053 | // The 8x8 square at superblock row 1, column 0, and the TX4 unit in |
| 12053 | 12054 | // its top-right corner (`col_off = 4`, `row_off = 0`): that unit's |
| 12054 | 12055 | // above-right answer is the BLOCK's, which is the whole reason a unit |
| @@ -12083,7 +12084,7 @@ mod tests { | ||
| 12083 | 12084 | /// wrong for one block size while looking plausible for the other. |
| 12084 | 12085 | #[test] |
| 12085 | 12086 | 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(); | |
| 12087 | 12088 | // Transcribed from has_top_right/has_bottom_left's row_off==0, |
| 12088 | 12089 | // col_off==0 (whole-transform) path, with MAX_MIB_SIZE_LOG2 = 5 (a |
| 12089 | 12090 | // 128px reference grid) pinned as libaom pins it, independent of the |
| @@ -12228,7 +12229,7 @@ mod tests { | ||
| 12228 | 12229 | |
| 12229 | 12230 | #[test] |
| 12230 | 12231 | 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(); | |
| 12232 | 12233 | let (width, height) = (SUPERBLOCK * 3, SUPERBLOCK * 3); |
| 12233 | 12234 | // Interior superblock, so neither the frame edge nor the col == 0 / |
| 12234 | 12235 | // last-row early returns answer instead of the table. |
| @@ -12263,7 +12264,7 @@ mod tests { | ||
| 12263 | 12264 | #[test] |
| 12264 | 12265 | fn odd_dimensions_are_refused() { |
| 12265 | 12266 | let _knobs = crate::speed::knob_read(); |
| 12266 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 12267 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 12267 | 12268 | for &(width, height) in &[(1921usize, 1080usize), (1920, 1081), (63, 63)] { |
| 12268 | 12269 | let picture = Picture::grey(width, height); |
| 12269 | 12270 | let err = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx) |
| @@ -12282,7 +12283,7 @@ mod tests { | ||
| 12282 | 12283 | #[test] |
| 12283 | 12284 | fn sequence_round_trips_at_a_non_multiple_size() { |
| 12284 | 12285 | let _knobs = crate::speed::knob_read(); |
| 12285 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 12286 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 12286 | 12287 | if !have_ffmpeg() { |
| 12287 | 12288 | eprintln!("SKIP sequence_round_trips_at_a_non_multiple_size: no ffmpeg"); |
| 12288 | 12289 | return; |
| @@ -12326,7 +12327,7 @@ mod tests { | ||
| 12326 | 12327 | #[test] |
| 12327 | 12328 | fn a_sequence_round_trips_at_the_exactly_half_straddle_size() { |
| 12328 | 12329 | let _knobs = crate::speed::knob_read(); |
| 12329 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 12330 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 12330 | 12331 | if !have_ffmpeg() { |
| 12331 | 12332 | eprintln!("SKIP a_sequence_round_trips_at_the_exactly_half_straddle_size: no ffmpeg"); |
| 12332 | 12333 | return; |
| @@ -12372,7 +12373,7 @@ mod tests { | ||
| 12372 | 12373 | #[test] |
| 12373 | 12374 | fn key_frame_and_inter_frame_both_encode_at_half_straddle_size() { |
| 12374 | 12375 | let _knobs = crate::speed::knob_read(); |
| 12375 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 12376 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 12376 | 12377 | let (width, height) = (640usize, 360usize); |
| 12377 | 12378 | let picture = Picture::grey(width, height); |
| 12378 | 12379 | 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 { | ||
| 12392 | 12393 | #[test] |
| 12393 | 12394 | fn a_640x360_half_straddle_round_trips_through_ffmpeg_across_three_frames() { |
| 12394 | 12395 | let _knobs = crate::speed::knob_read(); |
| 12395 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 12396 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 12396 | 12397 | if !have_ffmpeg() { |
| 12397 | 12398 | eprintln!( |
| 12398 | 12399 | "SKIP a_640x360_half_straddle_round_trips_through_ffmpeg_across_three_frames: \ |
| @@ -12418,7 +12419,7 @@ mod tests { | ||
| 12418 | 12419 | #[test] |
| 12419 | 12420 | fn a_640x360_half_straddle_sequence_round_trips_through_ffmpeg() { |
| 12420 | 12421 | let _knobs = crate::speed::knob_read(); |
| 12421 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 12422 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 12422 | 12423 | if !have_ffmpeg() { |
| 12423 | 12424 | eprintln!( |
| 12424 | 12425 | "SKIP a_640x360_half_straddle_sequence_round_trips_through_ffmpeg: no ffmpeg" |
| @@ -12478,7 +12479,7 @@ mod tests { | ||
| 12478 | 12479 | #[ignore = "a sweep, not a gate"] |
| 12479 | 12480 | fn probe_lambda() { |
| 12480 | 12481 | let _knobs = crate::speed::knob_read(); |
| 12481 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 12482 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 12482 | 12483 | let mut pictures = vec![ |
| 12483 | 12484 | ("test card".to_string(), test_card(160, 96)), |
| 12484 | 12485 | ("stripes".to_string(), stripes(160, 96, true)), |
| @@ -12510,7 +12511,7 @@ mod tests { | ||
| 12510 | 12511 | #[ignore = "a sweep, not a gate"] |
| 12511 | 12512 | fn probe_ladder() { |
| 12512 | 12513 | let _knobs = crate::speed::knob_read(); |
| 12513 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 12514 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 12514 | 12515 | for (name, picture) in sweep_pictures() { |
| 12515 | 12516 | let all = ladder(&picture, &KEY_FRAME_MODES, fctx); |
| 12516 | 12517 | let points = all |
| @@ -12529,7 +12530,7 @@ mod tests { | ||
| 12529 | 12530 | #[ignore = "a sweep, not a gate"] |
| 12530 | 12531 | fn probe_split() { |
| 12531 | 12532 | let _knobs = crate::speed::knob_read(); |
| 12532 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 12533 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 12533 | 12534 | for (name, picture) in sweep_pictures() { |
| 12534 | 12535 | let ladder = |split: bool| { |
| 12535 | 12536 | let mut points: Vec<(f64, f64)> = [110u8, 90, 70] |
| @@ -12611,7 +12612,7 @@ mod tests { | ||
| 12611 | 12612 | #[test] |
| 12612 | 12613 | fn every_mode_decodes_to_what_the_encoder_predicted() { |
| 12613 | 12614 | let _knobs = crate::speed::knob_write(); |
| 12614 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 12615 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 12615 | 12616 | if !have_ffmpeg() { |
| 12616 | 12617 | eprintln!("SKIP every_mode_decodes_to_what_the_encoder_predicted: no ffmpeg"); |
| 12617 | 12618 | return; |
| @@ -12655,7 +12656,7 @@ mod tests { | ||
| 12655 | 12656 | #[test] |
| 12656 | 12657 | fn the_search_picks_the_direction_the_picture_runs() { |
| 12657 | 12658 | let _knobs = crate::speed::knob_write(); |
| 12658 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 12659 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 12659 | 12660 | // Same confound as [`every_mode_decodes_to_what_the_encoder_predicted`]: |
| 12660 | 12661 | // a filter-intra block is coded `DC_PRED` whatever mode the arm |
| 12661 | 12662 | // offers, and these stripes are SCREEN content, where the filter arm |
| @@ -12763,7 +12764,7 @@ mod tests { | ||
| 12763 | 12764 | #[test] |
| 12764 | 12765 | fn the_search_beats_dc_alone() { |
| 12765 | 12766 | let _knobs = crate::speed::knob_read(); |
| 12766 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 12767 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 12767 | 12768 | for (name, picture, want) in [ |
| 12768 | 12769 | ("test card", test_card(160, 96), -0.05), |
| 12769 | 12770 | ("stripes", stripes(160, 96, true), -0.40), |
| @@ -12806,7 +12807,7 @@ mod tests { | ||
| 12806 | 12807 | #[ignore = "a sweep, not a gate"] |
| 12807 | 12808 | fn probe_directional() { |
| 12808 | 12809 | let _knobs = crate::speed::knob_write(); |
| 12809 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 12810 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 12810 | 12811 | for (name, picture) in sweep_pictures() { |
| 12811 | 12812 | let dc = ladder(&picture, &[DC_PRED], fctx); |
| 12812 | 12813 | let flat = ladder(&picture, &NON_DIRECTIONAL, fctx); |
| @@ -12881,7 +12882,7 @@ mod tests { | ||
| 12881 | 12882 | #[test] |
| 12882 | 12883 | fn the_search_picks_the_diagonal_the_picture_runs() { |
| 12883 | 12884 | let _knobs = crate::speed::knob_write(); |
| 12884 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 12885 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 12885 | 12886 | for (down_right, want) in [(true, D135_PRED), (false, D45_PRED)] { |
| 12886 | 12887 | let picture = diagonal(160, 96, down_right); |
| 12887 | 12888 | let (mode, count, blocks) = favourite_mode(&picture, fctx); |
| @@ -12901,7 +12902,7 @@ mod tests { | ||
| 12901 | 12902 | #[test] |
| 12902 | 12903 | fn the_diagonals_beat_the_modes_that_read_no_further() { |
| 12903 | 12904 | let _knobs = crate::speed::knob_read(); |
| 12904 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 12905 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 12905 | 12906 | for (name, picture, want) in [ |
| 12906 | 12907 | ("down-right", diagonal(160, 96, true), -0.20), |
| 12907 | 12908 | ("down-left", diagonal(160, 96, false), -0.20), |
| @@ -12925,7 +12926,7 @@ mod tests { | ||
| 12925 | 12926 | #[test] |
| 12926 | 12927 | fn a_mode_the_encoder_cannot_predict_is_refused() { |
| 12927 | 12928 | let _knobs = crate::speed::knob_read(); |
| 12928 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 12929 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 12929 | 12930 | let picture = test_card(64, 64); |
| 12930 | 12931 | let message = encode_key_frame_with_modes_with_ctx(&picture, 100, 0.5, &[13], fctx) |
| 12931 | 12932 | .unwrap_err() |
| @@ -12945,7 +12946,7 @@ mod tests { | ||
| 12945 | 12946 | #[test] |
| 12946 | 12947 | fn the_encoded_picture_is_the_one_that_went_in() { |
| 12947 | 12948 | let _knobs = crate::speed::knob_read(); |
| 12948 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 12949 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 12949 | 12950 | let picture = test_card(160, 96); |
| 12950 | 12951 | let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); |
| 12951 | 12952 | let luma = psnr(&encoded.reconstruction.y, &picture.y); |
| @@ -12968,7 +12969,7 @@ mod tests { | ||
| 12968 | 12969 | #[test] |
| 12969 | 12970 | fn fidelity_and_rate_move_with_the_quantizer() { |
| 12970 | 12971 | let _knobs = crate::speed::knob_read(); |
| 12971 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 12972 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 12972 | 12973 | let picture = test_card(128, 128); |
| 12973 | 12974 | let mut previous: Option<(usize, f64)> = None; |
| 12974 | 12975 | for &q in &[70u8, 90, 110] { |
| @@ -13029,7 +13030,7 @@ mod tests { | ||
| 13029 | 13030 | #[test] |
| 13030 | 13031 | fn a_flat_picture_costs_almost_nothing() { |
| 13031 | 13032 | let _knobs = crate::speed::knob_read(); |
| 13032 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 13033 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 13033 | 13034 | let mut picture = Picture::grey(128, 128); |
| 13034 | 13035 | picture.y.fill(97); |
| 13035 | 13036 | let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); |
| @@ -13066,7 +13067,7 @@ mod tests { | ||
| 13066 | 13067 | #[test] |
| 13067 | 13068 | fn a_picture_off_the_block_grid_encodes_and_a_malformed_one_is_refused() { |
| 13068 | 13069 | let _knobs = crate::speed::knob_read(); |
| 13069 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 13070 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 13070 | 13071 | encode_key_frame_with_ctx(&Picture::grey(40, 40), 100, 0.5, fctx) |
| 13071 | 13072 | .expect("40x40 cuts a 16x16 leaf on both axes, which is an inferred split"); |
| 13072 | 13073 | encode_key_frame_with_ctx(&Picture::grey(36, 40), 100, 0.5, fctx) |
| @@ -13150,7 +13151,7 @@ mod tests { | ||
| 13150 | 13151 | #[test] |
| 13151 | 13152 | fn a_single_axis_straddle_round_trips_through_ffmpeg() { |
| 13152 | 13153 | let _knobs = crate::speed::knob_read(); |
| 13153 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 13154 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 13154 | 13155 | if !have_ffmpeg() { |
| 13155 | 13156 | eprintln!("SKIP a_single_axis_straddle_round_trips_through_ffmpeg: no ffmpeg"); |
| 13156 | 13157 | return; |
| @@ -13180,7 +13181,7 @@ mod tests { | ||
| 13180 | 13181 | #[test] |
| 13181 | 13182 | fn a_frame_of_real_video_decodes_to_what_the_encoder_reconstructed() { |
| 13182 | 13183 | let _knobs = crate::speed::knob_read(); |
| 13183 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 13184 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 13184 | 13185 | let Ok(clip) = std::env::var("EC_AV1_CLIP") else { |
| 13185 | 13186 | eprintln!( |
| 13186 | 13187 | "SKIP a_frame_of_real_video_decodes_to_what_the_encoder_reconstructed: \ |
| @@ -13312,7 +13313,7 @@ mod tests { | ||
| 13312 | 13313 | #[test] |
| 13313 | 13314 | fn every_frame_of_a_sequence_decodes_to_what_the_encoder_reconstructed() { |
| 13314 | 13315 | let _knobs = crate::speed::knob_read(); |
| 13315 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 13316 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 13316 | 13317 | if !have_ffmpeg() { |
| 13317 | 13318 | eprintln!( |
| 13318 | 13319 | "SKIP every_frame_of_a_sequence_decodes_to_what_the_encoder_reconstructed: no ffmpeg" |
| @@ -13354,7 +13355,7 @@ mod tests { | ||
| 13354 | 13355 | #[test] |
| 13355 | 13356 | fn every_frame_of_a_sequence_decodes_through_our_own_decoder() { |
| 13356 | 13357 | let _knobs = crate::speed::knob_read(); |
| 13357 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 13358 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 13358 | 13359 | // 256x128, not the 128x64 this started at: once a leaf could search |
| 13359 | 13360 | // its second reference (lane-av1comp4) the small card's every |
| 13360 | 13361 | // eligible block went to a compound winner, which commits its flat |
| @@ -13420,7 +13421,7 @@ mod tests { | ||
| 13420 | 13421 | #[test] |
| 13421 | 13422 | fn predicted_coeff_bits_track_the_tile_the_writer_wrote() { |
| 13422 | 13423 | let _knobs = crate::speed::knob_read(); |
| 13423 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 13424 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 13424 | 13425 | let (width, height) = (256usize, 128usize); |
| 13425 | 13426 | let pictures: Vec<Picture> = (0..5) |
| 13426 | 13427 | .map(|i| panned_test_card(width, height, i * 2)) |
| @@ -13525,7 +13526,7 @@ mod tests { | ||
| 13525 | 13526 | #[test] |
| 13526 | 13527 | fn pricer_error_census_by_block_class() { |
| 13527 | 13528 | let _knobs = crate::speed::knob_read(); |
| 13528 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 13529 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 13529 | 13530 | let (width, height) = (256usize, 128usize); |
| 13530 | 13531 | let pictures: Vec<Picture> = (0..5) |
| 13531 | 13532 | .map(|i| panned_test_card(width, height, i * 2)) |
| @@ -13598,7 +13599,7 @@ mod tests { | ||
| 13598 | 13599 | assert!(!clips.is_empty(), "no source clip available"); |
| 13599 | 13600 | let (width, height, frames) = (640usize, 384usize, 6usize); |
| 13600 | 13601 | for (name, path) in &clips { |
| 13601 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 13602 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 13602 | 13603 | let source = clip_frames(path.to_str().unwrap(), "0", width, height, frames); |
| 13603 | 13604 | SCREEN_FRAMES.iter().for_each(|c| { |
| 13604 | 13605 | c.store(0, std::sync::atomic::Ordering::Relaxed); |
| @@ -13644,7 +13645,7 @@ mod tests { | ||
| 13644 | 13645 | #[test] |
| 13645 | 13646 | fn low_motion_makes_an_inter_frame_smaller_than_the_key_frame() { |
| 13646 | 13647 | let _knobs = crate::speed::knob_read(); |
| 13647 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 13648 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 13648 | 13649 | let (width, height) = (256usize, 128usize); |
| 13649 | 13650 | let pictures: Vec<Picture> = (0..5) |
| 13650 | 13651 | .map(|i| panned_test_card(width, height, i * 2)) |
| @@ -13682,7 +13683,7 @@ mod tests { | ||
| 13682 | 13683 | #[ignore = "a perf probe, not a gate"] |
| 13683 | 13684 | fn stage_timing_breakdown() { |
| 13684 | 13685 | let _knobs = crate::speed::knob_read(); |
| 13685 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 13686 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 13686 | 13687 | use std::time::Instant; |
| 13687 | 13688 | |
| 13688 | 13689 | for &(width, height) in &[(1920usize, 1080usize), (3840, 2160)] { |
| @@ -13805,7 +13806,7 @@ mod tests { | ||
| 13805 | 13806 | #[ignore = "a perf probe, not a gate"] |
| 13806 | 13807 | fn stage_timing_breakdown_inter() { |
| 13807 | 13808 | let _knobs = crate::speed::knob_read(); |
| 13808 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 13809 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 13809 | 13810 | use std::time::Instant; |
| 13810 | 13811 | |
| 13811 | 13812 | let (width, height) = (1280usize, 720); |
| @@ -13854,7 +13855,7 @@ mod tests { | ||
| 13854 | 13855 | #[ignore = "needs real clips and ffmpeg; prints numbers for the lane report to judge"] |
| 13855 | 13856 | fn prune_k_quality_sweep() { |
| 13856 | 13857 | let _knobs = crate::speed::knob_read(); |
| 13857 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 13858 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 13858 | 13859 | if !have_ffmpeg() { |
| 13859 | 13860 | eprintln!("SKIP prune_k_quality_sweep: no ffmpeg"); |
| 13860 | 13861 | return; |
| @@ -13955,7 +13956,7 @@ mod tests { | ||
| 13955 | 13956 | #[ignore = "needs real clips and ffmpeg; prints numbers for the lane report to judge"] |
| 13956 | 13957 | fn prune_k_quality_sweep_inter() { |
| 13957 | 13958 | let _knobs = crate::speed::knob_read(); |
| 13958 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 13959 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 13959 | 13960 | if !have_ffmpeg() { |
| 13960 | 13961 | eprintln!("SKIP prune_k_quality_sweep_inter: no ffmpeg"); |
| 13961 | 13962 | return; |
| @@ -14085,7 +14086,7 @@ mod tests { | ||
| 14085 | 14086 | #[test] |
| 14086 | 14087 | fn real_clip_encodes_within_its_quality_and_size_budget() { |
| 14087 | 14088 | let _knobs = crate::speed::knob_read(); |
| 14088 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 14089 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 14089 | 14090 | if !have_ffmpeg() { |
| 14090 | 14091 | eprintln!("SKIP real_clip_encodes_within_its_quality_and_size_budget: no ffmpeg"); |
| 14091 | 14092 | return; |
| @@ -14147,7 +14148,7 @@ mod tests { | ||
| 14147 | 14148 | #[test] |
| 14148 | 14149 | fn real_clip_encodes_within_its_quality_and_size_budget_at_a_straddle_size() { |
| 14149 | 14150 | let _knobs = crate::speed::knob_read(); |
| 14150 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 14151 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 14151 | 14152 | if !have_ffmpeg() { |
| 14152 | 14153 | eprintln!( |
| 14153 | 14154 | "SKIP real_clip_encodes_within_its_quality_and_size_budget_at_a_straddle_size: \ |
| @@ -14205,7 +14206,7 @@ mod tests { | ||
| 14205 | 14206 | #[ignore = "a perf probe, not a gate"] |
| 14206 | 14207 | fn sequence_bench_sanity() { |
| 14207 | 14208 | let _knobs = crate::speed::knob_read(); |
| 14208 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 14209 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 14209 | 14210 | use std::time::Instant; |
| 14210 | 14211 | let (width, height) = (1280usize, 720usize); |
| 14211 | 14212 | let pictures: Vec<Picture> = (0..24) |
| @@ -14229,7 +14230,7 @@ mod tests { | ||
| 14229 | 14230 | #[ignore = "a calibration probe, not a gate"] |
| 14230 | 14231 | fn calibration_sweep_base_q_idx() { |
| 14231 | 14232 | let _knobs = crate::speed::knob_read(); |
| 14232 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 14233 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 14233 | 14234 | if !have_ffmpeg() { |
| 14234 | 14235 | eprintln!("SKIP calibration_sweep_base_q_idx: no ffmpeg"); |
| 14235 | 14236 | return; |
| @@ -15216,7 +15217,7 @@ mod tests { | ||
| 15216 | 15217 | println!("| clip | ours PSNR/bytes per point | BD-rate vs libaom | BD-rate vs rav1e | wall ours:libaom:rav1e |"); |
| 15217 | 15218 | println!("|---|---|---|---|---|"); |
| 15218 | 15219 | for (name, path) in &clips { |
| 15219 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 15220 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 15220 | 15221 | let source = clip_frames(path.to_str().unwrap(), "0", width, height, frames); |
| 15221 | 15222 | let _ = take_partition_hits(); |
| 15222 | 15223 | let _ = crate::tile::take_palette_hits(); |
| @@ -15849,7 +15850,7 @@ mod tests { | ||
| 15849 | 15850 | println!("| clip | ours PSNR/bytes per point | BD-rate vs libaom | BD-rate vs rav1e | wall ours:libaom:rav1e (noisy) |"); |
| 15850 | 15851 | println!("|---|---|---|---|---|"); |
| 15851 | 15852 | for (name, path, seek) in &clips { |
| 15852 | - let fctx = &crate::decode::FrameCtx::new(); | |
| 15853 | + let fctx = &crate::decode::FrameCtx::for_encoder(); | |
| 15853 | 15854 | if probe_dims(path).is_none() { |
| 15854 | 15855 | eprintln!("SKIP {name}: ffprobe gave no size"); |
| 15855 | 15856 | continue; |
| @@ -16118,7 +16119,7 @@ mod tests { | ||
| 16118 | 16119 | "the probe's source differs from the gate's at the same window" |
| 16119 | 16120 | ); |
| 16120 | 16121 | 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()) | |
| 16122 | 16123 | .unwrap() |
| 16123 | 16124 | .stream |
| 16124 | 16125 | }; |
| @@ -16152,7 +16153,7 @@ mod tests { | ||
| 16152 | 16153 | let frames: usize = g("EC_PARITY_FRAMES").parse().unwrap(); |
| 16153 | 16154 | let q: u8 = g("EC_PARITY_Q").parse().unwrap(); |
| 16154 | 16155 | 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(); | |
| 16156 | 16157 | let e = encode_sequence_with_ctx(&source, q, 0.5, fctx).unwrap(); |
| 16157 | 16158 | let mut hash: u64 = 0xcbf2_9ce4_8422_2325; |
| 16158 | 16159 | for &b in &e.stream { |
crates/ec-av1/src/encoder.rsmodified+1 -1
| @@ -1191,7 +1191,7 @@ impl Av1Encoder { | ||
| 1191 | 1191 | reference: None, |
| 1192 | 1192 | next_index: 0, |
| 1193 | 1193 | rate_loop: None, |
| 1194 | - fctx: crate::decode::FrameCtx::new(), | |
| 1194 | + fctx: crate::decode::FrameCtx::for_encoder(), | |
| 1195 | 1195 | pyramid: None, |
| 1196 | 1196 | dpb: [const { None }; 8], |
| 1197 | 1197 | pending: Vec::new(), |