Mode ablations opt out of filter intra
Browse files at this commit0b03c13cb63101959ad1fc45bbf164f03041e9d0Parent: 24771c9- test
- mode ablations opt out of filter intra
- re-pin the encoder's own streams
1 changed file +34 -1
- crates/ec-av1/src/encode.rs +34 -1
crates/ec-av1/src/encode.rsmodified+34 -1
| @@ -1022,6 +1022,20 @@ pub(crate) fn force_screen(value: Option<bool>) { | ||
| 1022 | 1022 | SCREEN_FORCE.with(|c| c.set(value)); |
| 1023 | 1023 | } |
| 1024 | 1024 | |
| 1025 | +// lane-fintra: [`force_screen`] for the filter-intra candidate, so a MODE | |
| 1026 | +// ablation can measure the mode search alone. Setting it also clears the | |
| 1027 | +// sequence header's own `enable_filter_intra` bit, so the stream the arm | |
| 1028 | +// writes is exactly the one this encoder wrote before the lane. | |
| 1029 | +#[cfg(test)] | |
| 1030 | +thread_local! { | |
| 1031 | + static FILTER_INTRA_FORCE: std::cell::Cell<Option<bool>> = const { std::cell::Cell::new(None) }; | |
| 1032 | +} | |
| 1033 | + | |
| 1034 | +#[cfg(test)] | |
| 1035 | +pub(crate) fn force_filter_intra(value: Option<bool>) { | |
| 1036 | + FILTER_INTRA_FORCE.with(|c| c.set(value)); | |
| 1037 | +} | |
| 1038 | + | |
| 1025 | 1039 | pub(crate) fn arm_seq_screen(on: bool) { |
| 1026 | 1040 | SEQ_SCREEN.with(|c| c.set(on)); |
| 1027 | 1041 | } |
| @@ -4093,6 +4107,10 @@ fn cfl_on() -> bool { | ||
| 4093 | 4107 | /// its own on/off pair -- and how every byte pin written before it still |
| 4094 | 4108 | /// reproduces). |
| 4095 | 4109 | pub(crate) fn filter_intra_on() -> bool { |
| 4110 | + #[cfg(test)] | |
| 4111 | + if let Some(forced) = FILTER_INTRA_FORCE.with(std::cell::Cell::get) { | |
| 4112 | + return forced; | |
| 4113 | + } | |
| 4096 | 4114 | static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new(); |
| 4097 | 4115 | *ON.get_or_init(|| std::env::var("EC_AV1_FILTER_INTRA").as_deref() != Ok("0")) |
| 4098 | 4116 | } |
| @@ -11011,6 +11029,11 @@ mod tests { | ||
| 11011 | 11029 | eprintln!("SKIP every_mode_decodes_to_what_the_encoder_predicted: no ffmpeg"); |
| 11012 | 11030 | return; |
| 11013 | 11031 | } |
| 11032 | + // A mode ablation measures the MODE search: a filter-intra block is | |
| 11033 | + // coded `DC_PRED` whatever mode the arm forces, so it would fail the | |
| 11034 | + // "the encoder coded something else" check for a reason that is not | |
| 11035 | + // about the mode search at all. | |
| 11036 | + force_filter_intra(Some(false)); | |
| 11014 | 11037 | // 128 wide is a whole number of superblocks and 160 is not: the last |
| 11015 | 11038 | // superblock of a 160-wide row is half a one, whose blocks have no |
| 11016 | 11039 | // above-right samples inside the frame at all. |
| @@ -11121,6 +11144,10 @@ mod tests { | ||
| 11121 | 11144 | // these synthetic two-colour pictures losslessly under every arm and |
| 11122 | 11145 | // leave nothing to compare (see [`force_screen`]). |
| 11123 | 11146 | force_screen(Some(false)); |
| 11147 | + // Same reason, for the filter-intra candidate: it wins blocks under | |
| 11148 | + // BOTH arms of a mode ablation and so cancels the difference the | |
| 11149 | + // ablation measures (class `gate-recipe-confound`). | |
| 11150 | + force_filter_intra(Some(false)); | |
| 11124 | 11151 | let mut points: Vec<(f64, f64)> = [110u8, 90, 70] |
| 11125 | 11152 | .iter() |
| 11126 | 11153 | .map(|&q| { |
| @@ -12969,8 +12996,14 @@ mod tests { | ||
| 12969 | 12996 | // so every block taking either codes different syntax and different |
| 12970 | 12997 | // coefficients -- 8194 -> 7321 at q=150 and 28285 -> 27285 at q=60. |
| 12971 | 12998 | // `EC_AV1_CFL=0` / `EC_AV1_ANGLE=0` restore each half. |
| 12999 | + // Re-taken on lane-fintra: the sequence header sets | |
| 13000 | + // `enable_filter_intra`, so every DC_PRED intra block of at most | |
| 13001 | + // 32x32 without a luma palette carries a `use_filter_intra` flag and | |
| 13002 | + // the blocks that take one code a filter-intra mode, a different | |
| 13003 | + // prediction and different coefficients -- 7321 -> 7373 at q=150 and | |
| 13004 | + // 27285 -> 27074 at q=60. `EC_AV1_FILTER_INTRA=0` restores these. | |
| 12972 | 13005 | let pins: [(u8, usize, u64); 2] = |
| 12973 | - [(150, 7321, 0x34e2_e4e0_d7c5_09f3), (60, 27285, 0xbfd2_41af_dcac_a0c6)]; | |
| 13006 | + [(150, 7373, 0xd0af_b890_28bc_cfbf), (60, 27074, 0x8324_0e9f_5971_e4e7)]; | |
| 12974 | 13007 | for (q, bytes, hash) in pins { |
| 12975 | 13008 | let encoded = encode_sequence(&source, q, 0.5).unwrap(); |
| 12976 | 13009 | assert_eq!( |