From d1585d00bff858538a919b803b25f557524eb35c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 30 Aug 2026 08:05:14 +0300 Subject: [PATCH] fix(av1): inter frames' intra blocks inherited a stale enable_intra_edge_filter ENABLE_EDGE_FILTER is a thread-local set only by decode_key_frame_tile_with_cdfs; decode_inter_frame_tile never set it, so an inter frame's intra blocks read whatever the last key frame decoded on that thread left behind. Within one stream that is inert (its own key frame sets it first), but it makes decode impure across streams sharing a thread -- a real contamination path, and the shape that produces a suite-only flake. decode_stream now sets it from the sequence header for every stream, covering inter frames. Also teaches build-aom-oracle.sh to reconfigure a build tree that was configured under a different path instead of failing to regenerate. --- crates/ec-av1/src/decode.rs | 14 ++++++++++++++ crates/ec-av1/src/stream.rs | 5 +++++ scripts/build-aom-oracle.sh | 13 +++++++++++++ 3 files changed, 32 insertions(+) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 38aae01a..3a2b720a 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -391,6 +391,20 @@ thread_local! { static ENABLE_EDGE_FILTER: std::cell::Cell = const { std::cell::Cell::new(false) }; } +/// Set [`ENABLE_EDGE_FILTER`] for this thread. +/// +/// `decode_key_frame_tile_with_cdfs` sets it, but `decode_inter_frame_tile` +/// never did -- so an inter frame's intra blocks read whatever value the last +/// key frame decoded ON THIS THREAD left behind. Inside one stream that is +/// harmless (its own key frame sets it first), but a caller that decodes an +/// inter frame directly, or a test harness running several streams on one +/// thread, inherits a foreign sequence's bit: decode stops being a pure +/// function of the bitstream. `decode_stream` now calls this once per stream +/// from the sequence header, which covers every frame including inter ones. +pub(crate) fn set_enable_edge_filter(value: bool) { + ENABLE_EDGE_FILTER.with(|f| f.set(value)); +} + /// Current value of [`ANGLE_DELTA_HITS`]. pub(crate) fn angle_delta_hits() -> usize { ANGLE_DELTA_HITS.load(std::sync::atomic::Ordering::Relaxed) diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index ffc434b8..5841fa16 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -249,6 +249,11 @@ pub fn decode_stream(data: &[u8]) -> Result> { let enable_edge_filter = parser .sequence_header() .is_some_and(|seq| seq.enable_intra_edge_filter); + // Inter frames' intra blocks read this through a thread-local that only + // the key-frame tile path used to set; without this call a stream whose + // inter frames are decoded on a thread that previously decoded a + // different sequence would inherit that sequence's bit. + crate::decode::set_enable_edge_filter(enable_edge_filter); // lane-av1comp: `comp_group_idx`/`compound_idx`'s own gating bits. let enable_masked_compound = parser .sequence_header() diff --git a/scripts/build-aom-oracle.sh b/scripts/build-aom-oracle.sh index fcbefde3..f7f308c1 100755 --- a/scripts/build-aom-oracle.sh +++ b/scripts/build-aom-oracle.sh @@ -22,6 +22,19 @@ if [ ! -d "$SRC/.git" ]; then git clone --depth 1 --branch "$VERSION" https://aomedia.googlesource.com/aom "$SRC" fi +# A cmake build tree bakes in its own absolute path and its source's, so a +# build dir that was produced elsewhere and then moved cannot regenerate +# (`ninja: error: rebuilding build.ninja`) -- which silently costs you the +# ability to re-instrument aomdec later. Never stage a build under one name +# and rename it; configure it where it will live. If the cache disagrees with +# where we are now, drop it and reconfigure in place. +if [ -f "$BUILD/CMakeCache.txt" ] && + ! grep -q "^CMAKE_HOME_DIRECTORY:INTERNAL=$SRC$" "$BUILD/CMakeCache.txt"; then + echo "build tree was configured for a different path -- reconfiguring in place" >&2 + rm -f "$BUILD/CMakeCache.txt" + rm -rf "$BUILD/CMakeFiles" +fi + CPU_ARGS=() if [ -n "${AOM_TARGET_CPU:-}" ]; then CPU_ARGS=(-DAOM_TARGET_CPU="$AOM_TARGET_CPU")