Footage cache (#3271): a region of interest asks for rows only where the source reads rows

With a viewer region of interest the renderer asked a PNG still for some rows, which the media pool reads whole anyway, and the layer was left out of the layer cache: its masks and effects ran again on every render. FootageSource::reads_rows tells whether a source reads only the rows asked for (the media pool: an OpenEXR frame whose channels no effect reads); otherwise the renderer asks for the whole frame and the layer stays cached. A test renders a still twice under a region; it fails on the old code (two row reads instead of one whole read).
This commit is contained in:
vangel76 committed 2026-11-08 10:31:38 +01:00
1 parent 35788373cf
commit 74099e32bc
5 files changed
+76 -2

No files matched your search

+10
View File
@@ -45,6 +45,13 @@ pub trait FootageSource: Send + Sync {
let _ = rows;
self.frame_with(item, footage, t, size, float)
}
/// Whether [`FootageSource::frame_rows`] reads only the rows asked for of `footage` at `t`
/// (#3271). A source that reads the whole frame anyway leaves the default: the renderer then
/// asks for the whole frame, which its layer cache keeps.
fn reads_rows(&self, footage: &Footage, t: Tick) -> bool {
let _ = (footage, t);
false
}
/// `frames` interleaved stereo sample frames of `item`'s audio from source time `t` at
/// `rate` Hz (`None` when unavailable). The first sample is `t.to_units_floor(rate)`;
/// a sample boundary uses the earliest representable tick that selects that sample.
@@ -284,6 +291,9 @@ impl FootageSource for CancellableFootage<'_> {
fn frame_rows(&self, item: ItemId, footage: &Footage, t: Tick, size: Option<(u32, u32)>, float: FloatCurve, rows: (i64, i64)) -> Option<Arc<Image>> {
self.read(|| self.inner.frame_rows(item, footage, t, size, float, rows))
}
fn reads_rows(&self, footage: &Footage, t: Tick) -> bool {
self.inner.reads_rows(footage, t)
}
}
/// Footage that can be rasterised at any scale (SVG).
+2 -1
View File
@@ -962,7 +962,8 @@ impl<'a> Renderer<'a> {
return None;
}
let fx_margin = effects_margin(ctx, layer)?;
if comp_reads_pixels(ctx) {
// (a source that reads whole frames anyway: the whole frame, which the layer cache keeps)
if comp_reads_pixels(ctx) || !self.footage.reads_rows(f, ctx.source_time(layer)) {
return None;
}
let inv = ctx.world_matrix(layer).inverse()?;
+47
View File
@@ -140,3 +140,50 @@ fn exr_sequence_layers_are_cached_per_frame() {
assert_eq!(src.sizes.unwrap().into_inner().unwrap().len(), fetches, "{ext}");
}
}
/// #3271 review: with a viewer region of interest, a still from a source that reads whole frames
/// anyway (not by rows) is asked for whole and stays in the layer cache: a second render reads
/// nothing. A source that reads rows is asked for only the rows the region shows.
#[test]
fn a_source_that_reads_whole_frames_keeps_the_layer_cached_under_a_region() {
struct Counting {
reads: Mutex<Vec<Option<(i64, i64)>>>,
by_rows: bool,
}
impl FootageSource for Counting {
fn frame(&self, item: ItemId, f: &Footage, t: Tick) -> Option<Arc<Image>> {
self.reads.lock().unwrap().push(None);
Clip { sizes: None }.frame(item, f, t)
}
fn frame_rows(&self, item: ItemId, f: &Footage, t: Tick, _: Option<(u32, u32)>, _: crate::FloatCurve, rows: (i64, i64)) -> Option<Arc<Image>> {
self.reads.lock().unwrap().push(Some(rows));
Clip { sizes: None }.frame(item, f, t)
}
fn reads_rows(&self, _: &Footage, _: Tick) -> bool {
self.by_rows
}
}
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::Still;
f.path = "/still.png".into();
}
let opts = RenderOpts { roi: Some([0.0, 0.0, 96.0, 10.0]), ..Default::default() };
for by_rows in [false, true] {
let src = Counting { reads: Mutex::default(), by_rows };
let cache = crate::LayerCache::default();
for _ in 0..2 {
let mut r = Renderer::new(&p, &src, opts);
r.cache = Some(&cache);
r.comp_frame(cid, Tick::ZERO);
}
let reads = src.reads.into_inner().unwrap();
if by_rows {
assert_eq!(reads.len(), 2, "by rows, each render: {reads:?}");
assert!(reads.iter().all(|r| r.is_some_and(|(y0, y1)| y0 == 0 && y1 < 54)), "{reads:?}");
} else {
assert_eq!(reads, [None], "whole, once: the layer cache keeps it");
}
}
}