Footage cache (#3271): plan the aux channels before the render

FootageSource gains aux_for (only what a need reads), aux_names (names from the headers) and
set_aux_needs (per footage file, what its effects read, so the picture is decoded with those
channels in one pass); the wrappers forward them. The renderer asks for the union of the layer's
effects' needs; the engine sends each aux footage's needs with the aux footage set (all channels
when a parameter is animated or an effect doesn't say); layer.channels and the popups read names
only.
This commit is contained in:
vangel76 committed 2026-11-08 01:55:41 +01:00
1 parent 14e0665ef4
commit 089f8e374d
8 files changed
+115 -4

No files matched your search

+12
View File
@@ -389,10 +389,22 @@ impl FootageSource for ConfinedFootage {
fn aux(&self, item: ItemId, footage: &Footage, t: Tick) -> Option<Arc<AuxChannels>> {
self.readable(footage).then(|| self.inner.aux(item, footage, t)).flatten()
}
/// The channels `need` reads of the footage frame, or `None` when the footage lies outside the allowed roots.
fn aux_for(&self, item: ItemId, footage: &Footage, t: Tick, need: &effectcraft_engine::raster::channels3d::AuxNeed) -> Option<Arc<AuxChannels>> {
self.readable(footage).then(|| self.inner.aux_for(item, footage, t, need)).flatten()
}
/// The channel names of the footage frame, or `None` when the footage lies outside the allowed roots.
fn aux_names(&self, item: ItemId, footage: &Footage, t: Tick) -> Option<Arc<AuxChannels>> {
self.readable(footage).then(|| self.inner.aux_names(item, footage, t)).flatten()
}
/// Forwards the auxiliary footage paths to the inner source.
fn set_aux_footage(&self, paths: &[String]) {
self.inner.set_aux_footage(paths)
}
/// Forwards what effects read of each auxiliary footage to the inner source.
fn set_aux_needs(&self, needs: &[(String, effectcraft_engine::raster::channels3d::AuxNeed)]) {
self.inner.set_aux_needs(needs)
}
/// The 3D model for the footage, or `None` when the footage lies outside the allowed roots.
fn model(&self, item: ItemId, footage: &Footage) -> Option<Arc<effectcraft_model::Model>> {
self.readable(footage).then(|| self.inner.model(item, footage)).flatten()
+5 -3
View File
@@ -422,7 +422,7 @@ struct CryptoHit {
impl CryptoHit {
fn manifest(&self) -> Option<&[(String, u32)]> {
self.aux.manifests.iter().find(|(l, _)| *l == self.layer).map(|(_, m)| m.as_slice())
self.aux.manifest(&self.layer)
}
fn reply(&self, sel: &str) -> Value {
let selected = effectcraft_effects::selection_hashes(sel, self.manifest()).contains(&self.hash);
@@ -1259,12 +1259,14 @@ fn list(_: &mut Session, p: &Value) -> Result<Value> {
impl Session {
/// The named channels of layer `lid` in the active comp at the current time: its
/// multi-layer OpenEXR footage's layers and channels (`diffuse.R`, `depth.Z`, …), which
/// EXtractoR and the 3D Channel effects read. `None` for other layers.
/// EXtractoR and the 3D Channel effects read, and its Cryptomatte manifests. The names come
/// from the file's headers ([`effectcraft_render::FootageSource::aux_names`]): the planes
/// may be empty, so this is for lists and popups only. `None` for other layers.
pub fn layer_channels(&self, lid: LayerId) -> Option<std::sync::Arc<effectcraft_raster::AuxChannels>> {
let layer = self.active_comp()?.layer(lid)?;
let effectcraft_project::LayerSource::Footage { item } = layer.source else { return None };
let effectcraft_project::ItemKind::Footage(f) = &self.project.item(item)?.kind else { return None };
self.footage.aux(item, f, layer.layer_time(self.time()))
self.footage.aux_names(item, f, layer.layer_time(self.time()))
}
}
+1
View File
@@ -91,6 +91,7 @@ fn render_project(host: &Session, path: &Path) -> Value {
// The project shared `host`'s footage source and gave it its own set of footage effects read
// the channels of (#474): give back the host's.
host.footage.set_aux_footage(host.aux_footage.as_deref().unwrap_or(&[]));
host.footage.set_aux_needs(host.aux_needs.as_deref().unwrap_or(&[]));
let mut v = match result {
Ok(v) => v,
Err(e) => json!({"state": "failed", "error": e, "items": []}),
+4
View File
@@ -260,6 +260,9 @@ pub struct Session {
/// The footage files effects read the channels of, as last given to the footage source
/// ([`Session::refresh_aux_footage`]); `None` = not given yet.
pub aux_footage: Option<Vec<String>>,
/// What the effects read of each of those files, as last given ([`Session::refresh_aux_footage`],
/// #3271); `None` = not given yet.
pub aux_needs: Option<Vec<(String, effectcraft_raster::channels3d::AuxNeed)>>,
/// How many script-issued commands are running ([`Session::execute_for_script`]): while one
/// is, settings that guard what scripts may do can't change (see
/// [`prefs::Scripting::same_permissions`]).
@@ -388,6 +391,7 @@ impl Default for Session {
stored_paths: Default::default(),
footage_stamps: Default::default(),
aux_footage: None,
aux_needs: None,
script_calls: ScriptCalls::default(),
}
}
+1
View File
@@ -220,6 +220,7 @@ impl Session {
self.project = Arc::new(p);
// The set of footage effects read the channels of is sent again, even when it is empty.
self.aux_footage = None;
self.aux_needs = None;
self.history = History::default();
self.state = EditorState { snapping: true, view_layout: 1, ..Default::default() };
self.path = path;
+42
View File
@@ -155,9 +155,51 @@ impl Session {
self.footage.set_aux_footage(&paths);
self.aux_footage = Some(paths);
}
let needs = aux_needs(&self.project);
if self.aux_needs.as_ref() != Some(&needs) {
self.footage.set_aux_needs(&needs);
self.aux_needs = Some(needs);
}
}
}
/// What the effects of [`aux_footage`]'s layers read of each file's channels (#3271), by
/// [`effectcraft_project::Footage::path`], sorted: the union of what each enabled effect reading
/// them declares ([`effectcraft_effects::aux_needs`]) with its parameters' values. An effect that
/// doesn't declare, or whose parameters change over time (keyframes, an expression), reads all
/// channels. Several layers of one file add up.
pub(crate) fn aux_needs(project: &effectcraft_project::Project) -> Vec<(String, effectcraft_raster::channels3d::AuxNeed)> {
use effectcraft_project::{GroupKind, ItemKind, LayerSource, Node};
use effectcraft_raster::channels3d::AuxNeed;
let mut out: std::collections::BTreeMap<String, AuxNeed> = std::collections::BTreeMap::new();
for l in project.comps().flat_map(|(_, c)| c.layers.iter()).filter(|l| l.switches.effects) {
let LayerSource::Footage { item } = &l.source else { continue };
let Some(ItemKind::Footage(f)) = project.item(*item).map(|i| &i.kind) else { continue };
if f.path.is_empty() {
continue;
}
for g in l.effects().into_iter().flat_map(|fx| fx.groups()).filter(|g| g.enabled) {
let GroupKind::Effect { effect } = &g.kind else { continue };
if !effectcraft_effects::reads_aux(effect) {
continue;
}
let moving = g.children.iter().any(|c| matches!(c, Node::Prop(p) if p.is_animated() || p.has_expression()));
let need = if moving {
AuxNeed::All
} else {
let params = effectcraft_effects::flatten_params(g, &mut |p| p.value.clone());
effectcraft_effects::aux_needs(effect, &params).map_or(AuxNeed::All, AuxNeed::Lookups)
};
let merged = match out.remove(&f.path) {
Some(e) => e.union(need),
None => need,
};
out.insert(f.path.clone(), merged);
}
}
out.into_iter().collect()
}
/// The files (each footage item's [`effectcraft_project::Footage::path`], sorted, once each) of
/// the footage layers that have an enabled effect reading their channels
/// ([`effectcraft_effects::reads_aux`]), with the layer's Effects switch on. Several items can
+24 -1
View File
@@ -224,7 +224,9 @@ impl<'a> Renderer<'a> {
LayerSource::Footage { item } => {
let item = ctx.media_item(layer, *item);
let ItemKind::Footage(f) = &self.project.item(item)?.kind else { return None };
let a = self.read(|| self.footage.aux(item, f, ctx.source_time(layer)))?;
// Only what the layer's effects read (#3271).
let need = self.layer_aux_need(ctx, layer);
let a = self.read(|| self.footage.aux_for(item, f, ctx.source_time(layer), &need))?;
// Aux pixels per layer pixel (the layer is the footage at its nominal size). The
// planes are only copied when that changes the scale.
let scale = a.width as f64 / f.width as f64;
@@ -245,6 +247,27 @@ impl<'a> Renderer<'a> {
}
}
/// What the enabled effects of `layer` read of its auxiliary channels at the context time
/// ([`effectcraft_effects::aux_needs`], #3271): the union of their lookups, or all channels
/// when one doesn't say (or none reads them).
pub fn layer_aux_need(&self, ctx: &EvalCtx, layer: &Layer) -> effectcraft_raster::channels3d::AuxNeed {
use effectcraft_raster::channels3d::AuxNeed;
let mut need: Option<AuxNeed> = None;
for g in layer.effects().into_iter().flat_map(|fx| fx.groups()).filter(|g| g.enabled) {
let effectcraft_project::GroupKind::Effect { effect } = &g.kind else { continue };
if !effectcraft_effects::reads_aux(effect) {
continue;
}
let params = effectcraft_effects::flatten_params(g, &mut |pr| ctx.value(layer, pr));
let one = effectcraft_effects::aux_needs(effect, &params).map_or(AuxNeed::All, AuxNeed::Lookups);
need = Some(match need {
Some(n) => n.union(one),
None => one,
});
}
need.unwrap_or_default()
}
/// Evaluation context of comp `comp_id` at comp time `t`.
pub fn eval_ctx(&self, comp_id: ItemId, t: Tick) -> Option<EvalCtx<'a>> {
Some(self.ctx(comp_id, self.project.comp(comp_id)?, t))
+26
View File
@@ -49,12 +49,29 @@ pub trait FootageSource: Send + Sync {
fn aux(&self, _item: ItemId, _footage: &Footage, _t: Tick) -> Option<Arc<effectcraft_raster::AuxChannels>> {
None
}
/// [`FootageSource::aux`] of only what `need` reads (#3271): the channels its lookups find,
/// or more (sources may hand over a set that holds them; [`effectcraft_raster::AuxChannels::listed`]
/// then names every channel). Sources that read every channel anyway can leave the default.
fn aux_for(&self, item: ItemId, footage: &Footage, t: Tick, need: &effectcraft_raster::channels3d::AuxNeed) -> Option<Arc<effectcraft_raster::AuxChannels>> {
let _ = need;
self.aux(item, footage, t)
}
/// The channel names of [`FootageSource::aux`] (planes may be empty: read from the file's
/// headers alone), for channel lists and popups. Never handed to an effect.
fn aux_names(&self, item: ItemId, footage: &Footage, t: Tick) -> Option<Arc<effectcraft_raster::AuxChannels>> {
self.aux(item, footage, t)
}
/// The footage files (by [`Footage::path`]) whose channels effects of the project read
/// through [`FootageSource::aux`] (EXtractoR, Cryptomatte and the other 3D Channel effects),
/// replacing the set given before. A source that decodes a file's picture and its channels
/// separately can decode both at once for these from the first frame on. Sources that don't
/// ignore it.
fn set_aux_footage(&self, _paths: &[String]) {}
/// What the effects reading the channels of each footage file (by [`Footage::path`], as
/// [`FootageSource::set_aux_footage`] names them) read of them (#3271), replacing what was
/// given before: the picture of such footage is then decoded together with those channels
/// only. A file not named here reads every channel. Sources that don't care ignore it.
fn set_aux_needs(&self, _needs: &[(String, effectcraft_raster::channels3d::AuxNeed)]) {}
/// The parsed 3D model of a [`effectcraft_project::FootageKind::Model`] item (Advanced 3D).
fn model(&self, _item: ItemId, _footage: &Footage) -> Option<Arc<effectcraft_model::Model>> {
None
@@ -174,9 +191,18 @@ impl FootageSource for CancellableFootage<'_> {
fn aux(&self, item: ItemId, footage: &Footage, t: Tick) -> Option<Arc<effectcraft_raster::AuxChannels>> {
self.inner.aux(item, footage, t)
}
fn aux_for(&self, item: ItemId, footage: &Footage, t: Tick, need: &effectcraft_raster::channels3d::AuxNeed) -> Option<Arc<effectcraft_raster::AuxChannels>> {
self.inner.aux_for(item, footage, t, need)
}
fn aux_names(&self, item: ItemId, footage: &Footage, t: Tick) -> Option<Arc<effectcraft_raster::AuxChannels>> {
self.inner.aux_names(item, footage, t)
}
fn set_aux_footage(&self, paths: &[String]) {
self.inner.set_aux_footage(paths)
}
fn set_aux_needs(&self, needs: &[(String, effectcraft_raster::channels3d::AuxNeed)]) {
self.inner.set_aux_needs(needs)
}
fn model(&self, item: ItemId, footage: &Footage) -> Option<Arc<effectcraft_model::Model>> {
self.inner.model(item, footage)
}