From b54030b39c7a54a73893692eb595545d17ba927d Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sun, 8 Nov 2026 02:54:01 +0100 Subject: [PATCH] Footage cache (#3271): OpenEXR sequence layers are layer-cached per frame key_any keys an OpenEXR sequence layer (no proxy) by item and source time as it keys stills, so a processed frame is kept in RAM and on disk; its entries list the frame file they read, so Reload Footage and a changed file drop them as before. --- crates/render/src/cache.rs | 23 ++++++++++++----- crates/render/src/tests/footage_size.rs | 34 +++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/crates/render/src/cache.rs b/crates/render/src/cache.rs index 8a3d7b8ae..a86b75d3f 100644 --- a/crates/render/src/cache.rs +++ b/crates/render/src/cache.rs @@ -700,11 +700,22 @@ fn history_unkeyable(layer: &Layer, effects: Option) -> bool { reads_other_times(layer, effects) && layer.props.children.iter().any(|c| matches!(c, Node::Group(g) if g.match_id != "transform" && has_expression(g))) } -/// A still image (no proxy): its layer is cached like a text or shape layer, so the GPU -/// compositor uploads it once, not every frame (#1812: four 21120 px plates re-uploaded by every -/// preview worker ran the GPU out of memory). Movies and sequences stay in the media pool only. -fn still_footage(ctx: &EvalCtx, item: effectcraft_project::ItemId) -> bool { - ctx.project.item(item).is_some_and(|it| it.proxy.is_none() && matches!(&it.kind, ItemKind::Footage(f) if f.kind == FootageKind::Still)) +/// Footage whose processed layer is cached (keyed by item and source time for all but stills): +/// - a still image (no proxy): its layer is cached like a text or shape layer, so the GPU +/// compositor uploads it once, not every frame (#1812: four 21120 px plates re-uploaded by +/// every preview worker ran the GPU out of memory); +/// - an OpenEXR sequence (no proxy, #3271): each frame is a file read whole and its effects +/// (EXtractoR, Cryptomatte, depth effects) are costly, so a processed frame is worth keeping in +/// RAM and on disk. Its entries list the frame file they read, so Reload Footage and a changed +/// file drop them as any other. +/// +/// Movies and other sequences stay in the media pool only. +fn cached_footage(ctx: &EvalCtx, item: effectcraft_project::ItemId) -> bool { + ctx.project.item(item).is_some_and(|it| { + it.proxy.is_none() + && matches!(&it.kind, ItemKind::Footage(f) if f.kind == FootageKind::Still + || (f.kind == FootageKind::Sequence && f.sequence.first().is_some_and(|p| p.to_ascii_lowercase().ends_with(".exr")))) + }) } /// Does the layer have an animated mask that motion blur may draw at other times (Layer ▸ Mask ▸ @@ -779,7 +790,7 @@ fn key_any(ctx: &EvalCtx, layer: &Layer, scale: f64, draft: bool, blur: bool, fo hash_debug(&mut h, s); } LayerSource::Text | LayerSource::Shape => {} - LayerSource::Footage { item } if footage || still_footage(ctx, ctx.media_item(layer, *item)) => { + LayerSource::Footage { item } if footage || cached_footage(ctx, ctx.media_item(layer, *item)) => { let item = ctx.media_item(layer, *item); let it = ctx.project.item(item)?; let ItemKind::Footage(f) = &it.kind else { return None }; diff --git a/crates/render/src/tests/footage_size.rs b/crates/render/src/tests/footage_size.rs index 065941d8a..273184ec8 100644 --- a/crates/render/src/tests/footage_size.rs +++ b/crates/render/src/tests/footage_size.rs @@ -106,3 +106,37 @@ fn still_layers_are_cached_across_times_and_movies_are_not() { assert_eq!(src.sizes.unwrap().into_inner().unwrap().len(), fetches + 3, "{kind:?}"); } } + +/// #3271: an OpenEXR sequence's layer is cached per frame (keyed by its source time): the same +/// frame again is served from the layer cache, another frame has another key. Other sequences +/// stay in the media pool only. +#[test] +fn exr_sequence_layers_are_cached_per_frame() { + for (ext, fetches) in [("exr", 1), ("png", 2)] { + let (mut p, cid) = project(BitDepth::Bpc8, false); + let Some(LayerSource::Footage { item }) = p.comp(cid).map(|c| c.layers[0].source.clone()) else { panic!("footage layer") }; + if let Some(ItemKind::Footage(f)) = p.item_mut(item).map(|it| &mut it.kind) { + f.kind = FootageKind::Sequence; + f.sequence = (1..=30).map(|i| format!("/shot/plate_{i:04}.{ext}")).collect(); + f.path = f.sequence[0].clone(); + } + let key = |t: f64| { + let c = p.comp(cid).unwrap(); + crate::cache::layer_key(&crate::EvalCtx::new(&p, cid, c, Tick::from_seconds_f64(t)), &c.layers[0], 0.5, false, false) + }; + assert_eq!(key(0.0).is_some(), ext == "exr", "{ext}"); + if ext == "exr" { + assert_ne!(key(0.0), key(0.1), "another frame, another key"); + assert_eq!(key(0.0), key(0.01), "the same frame"); + } + let cache = crate::LayerCache::default(); + let src = Clip { sizes: Some(Mutex::default()) }; + let opts = RenderOpts { scale: 0.5, ..Default::default() }; + for _ in 0..2 { + let mut r = Renderer::new(&p, &src, opts); + r.cache = Some(&cache); + r.comp_frame(cid, Tick::ZERO); + } + assert_eq!(src.sizes.unwrap().into_inner().unwrap().len(), fetches, "{ext}"); + } +}