forge
Explore
Log in

Don't you dare go Hollow

The intra-mode ablations force the palette off

Browse files at this commit

cf280e5aa9eeaf426419a18b70d44d8dbbf227acAhmet Kaan GümüşParent: 55cb55e
  • test
    • the intra-mode ablations force the palette off
Show full message
test(av1): the intra-mode ablations force the palette off

A two-colour synthetic picture is coded losslessly by the palette under every
arm of a mode ablation, so both ladders reach infinite PSNR and the ablation
measures nothing (three tests failed exactly that way). `force_screen` is a
per-thread override -- the suite runs in one process, so an environment
variable could not do it.
crates/ec-av1/src/encode.rsmodified+27 -0
@@ -725,6 +725,21 @@ thread_local! {
725725 static SEQ_SCREEN: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
726726 }
727727
728+thread_local! {
729+ /// Overrides [`screen_content`] for the calling thread, which is what the
730+ /// intra-MODE ablations use: on a two-colour synthetic picture the palette
731+ /// codes every block losslessly, so both arms of a mode ablation reach
732+ /// infinite PSNR and the ablation measures nothing at all (the
733+ /// `fixture-proves-the-symbol-not-the-signal` class). An environment
734+ /// variable cannot do this -- the tests run in one process, in parallel.
735+ static SCREEN_FORCE: std::cell::Cell<Option<bool>> = const { std::cell::Cell::new(None) };
736+}
737+
738+#[cfg(test)]
739+pub(crate) fn force_screen(value: Option<bool>) {
740+ SCREEN_FORCE.with(|c| c.set(value));
741+}
742+
728743 pub(crate) fn arm_seq_screen(on: bool) {
729744 SEQ_SCREEN.with(|c| c.set(on));
730745 }
@@ -776,6 +791,10 @@ pub(crate) static SCREEN_FRAMES: [std::sync::atomic::AtomicUsize; 2] =
776791 /// cover more than a [`screen_pct`]th of the frame. `width` is the plane's
777792 /// stride, `true_*` the frame's real (decodable) extent.
778793 fn screen_content(y: &[u8], width: usize, true_width: usize, true_height: usize) -> bool {
794+ if let Some(forced) = SCREEN_FORCE.with(std::cell::Cell::get) {
795+ SCREEN_FRAMES[usize::from(forced)].fetch_add(1, std::sync::atomic::Ordering::Relaxed);
796+ return forced;
797+ }
779798 if let Ok(v) = std::env::var("EC_AV1_SCREEN") {
780799 let on = v != "0";
781800 SCREEN_FRAMES[usize::from(on)].fetch_add(1, std::sync::atomic::Ordering::Relaxed);
@@ -6792,6 +6811,10 @@ mod tests {
67926811 /// A ladder of (luma PSNR, log10 bytes) for one mode set, ordered by
67936812 /// fidelity.
67946813 fn ladder(picture: &Picture, modes: &[u8], fctx: &crate::decode::FrameCtx) -> Vec<(f64, f64)> {
6814+ // A mode ablation measures the MODE search: the palette would code
6815+ // these synthetic two-colour pictures losslessly under every arm and
6816+ // leave nothing to compare (see [`force_screen`]).
6817+ force_screen(Some(false));
67956818 let mut points: Vec<(f64, f64)> = [110u8, 90, 70]
67966819 .iter()
67976820 .map(|&q| {
@@ -6904,6 +6927,10 @@ mod tests {
69046927 /// The mode picked by the most blocks of a picture, ignoring the first
69056928 /// block, which has no neighbours to tell the modes apart with.
69066929 fn favourite_mode(picture: &Picture, fctx: &crate::decode::FrameCtx) -> (u8, usize, usize) {
6930+ // A mode ablation measures the MODE search: the palette would code
6931+ // these synthetic two-colour pictures losslessly under every arm and
6932+ // leave nothing to compare (see [`force_screen`]).
6933+ force_screen(Some(false));
69076934 let encoded = encode_key_frame_with_ctx(picture, 100, 0.5, fctx).unwrap();
69086935 let blocks = &encoded.modes[1..];
69096936 let mut counts = [0usize; 13];