From 612419f3c1ca71943ee3b44f4ae321f25eaabaa1 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sun, 8 Nov 2026 16:09:52 +0100 Subject: [PATCH] Footage cache (#3271): a render's channel reads are called off with the render The cancellable footage view passed aux and aux_for straight to the source, so a viewer render called off during a channel decode kept decoding. They now go through the render's cancel flag like frame reads (a decode stops between batches; once called off none starts). A test checks a channel read runs under the flag and none starts after; it fails on the old code. --- crates/render/src/footage.rs | 5 ++-- crates/render/src/tests/footage_size.rs | 38 +++++++++++++++++++++++++ docs/effects.md | 2 -- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/crates/render/src/footage.rs b/crates/render/src/footage.rs index 9eff834f3..6e7111e73 100644 --- a/crates/render/src/footage.rs +++ b/crates/render/src/footage.rs @@ -221,8 +221,9 @@ impl FootageSource for CancellableFootage<'_> { fn audio(&self, item: ItemId, footage: &Footage, t: Tick, frames: usize, rate: u32) -> Option> { self.inner.audio(item, footage, t, frames, rate) } + // (decoding channels is a read like a frame's: called off with the render, between batches) fn aux(&self, item: ItemId, footage: &Footage, t: Tick) -> Option> { - self.inner.aux(item, footage, t) + self.read(|| self.inner.aux(item, footage, t)) } fn aux_for( &self, @@ -231,7 +232,7 @@ impl FootageSource for CancellableFootage<'_> { t: Tick, need: &effectcraft_raster::channels3d::AuxNeed, ) -> Option> { - self.inner.aux_for(item, footage, t, need) + self.read(|| self.inner.aux_for(item, footage, t, need)) } fn aux_names(&self, item: ItemId, footage: &Footage, t: Tick) -> Option> { self.inner.aux_names(item, footage, t) diff --git a/crates/render/src/tests/footage_size.rs b/crates/render/src/tests/footage_size.rs index 3ddccdb44..004164859 100644 --- a/crates/render/src/tests/footage_size.rs +++ b/crates/render/src/tests/footage_size.rs @@ -187,3 +187,41 @@ fn a_source_that_reads_whole_frames_keeps_the_layer_cached_under_a_region() { } } } + +/// #3271 review: a render's channel reads (an effect's EXR channels) are called off with the +/// render like its frame reads: they run under the render's cancel flag (a decode stops between +/// batches), and once it is set they don't start. +#[test] +fn channel_reads_are_called_off_with_the_render() { + use std::sync::atomic::{AtomicBool, Ordering}; + thread_local! { + static UNDER: std::cell::Cell = const { std::cell::Cell::new(false) }; + } + #[derive(Default)] + struct Channels { + reads: Mutex>, + } + impl FootageSource for Channels { + fn frame(&self, _: ItemId, _: &Footage, _: Tick) -> Option> { + None + } + fn cancellable(&self, _: &Arc, f: &mut dyn FnMut()) { + UNDER.with(|u| u.set(true)); + f(); + UNDER.with(|u| u.set(false)); + } + fn aux_for(&self, _: ItemId, f: &Footage, _: Tick, _: &effectcraft_raster::channels3d::AuxNeed) -> Option> { + self.reads.lock().unwrap().push(UNDER.with(|u| u.get())); + Some(Arc::new(effectcraft_raster::AuxChannels::new(f.width, f.height, 1.0))) + } + } + let inner = Channels::default(); + let cancel = Arc::new(AtomicBool::new(false)); + let src = crate::CancellableFootage { inner: &inner, cancel: cancel.clone() }; + let f = Footage { width: 4, height: 2, ..Default::default() }; + let need = effectcraft_raster::channels3d::AuxNeed::Lookups(vec![]); + assert!(src.aux_for(ItemId(1), &f, Tick::ZERO, &need).is_some()); + cancel.store(true, Ordering::Relaxed); + assert!(src.aux_for(ItemId(1), &f, Tick::ZERO, &need).is_none(), "called off"); + assert_eq!(*inner.reads.lock().unwrap(), [true], "read once, under the render's flag"); +} diff --git a/docs/effects.md b/docs/effects.md index 96893fe4e..d9f726481 100644 --- a/docs/effects.md +++ b/docs/effects.md @@ -13,8 +13,6 @@ Effects are addressed by id (`ec..`) or display name in commands ## 3D Channel -The parameters that pick which channels or Cryptomatte layer an effect reads are not animatable, as in After Effects (see [footage](footage.md)). - | Effect | Id | Params | GPU | 32 | Status | |---|---|---:|:-:|:-:|---| | 3D Channel Extract | `ec.3d.channelextract` | 6 | GPU | 32 | Implemented |