mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-20 09:05:51 +00:00
Render: sampleImage and text fonts note the files they read
EvalCtx carries the render's read log. A sampleImage render records its footage reads, keeps them with its per-thread cached buffer and notes them in the evaluating render's log on every use. Text notes the font files it is drawn with, with the identity their bytes were read with; a family that isn't installed, a fallback or missing glyph, or a font from memory leaves the list incomplete. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8d948c231c
commit
d04ccd5234
38 files changed
+298
-24
No files matched your search
@@ -4,13 +4,16 @@
|
||||
//! expression (its footage source; [`EvalCtx::footage`]): source → masks → effects for
|
||||
//! `postEffect = true`, the bare source otherwise, in layer space (before the transform). Buffers
|
||||
//! are cached per thread for the frame, so many expressions sampling the same layer at the same
|
||||
//! time render it once.
|
||||
//! time render it once. The source files a sampled render reads are kept with its buffer and
|
||||
//! noted in the evaluating render's log ([`EvalCtx::reads`]) on every use, so a frame whose
|
||||
//! expressions sample footage lists that footage too (#3184).
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use effectcraft_project::{ItemId, Layer};
|
||||
use effectcraft_render::reads::{ReadFiles, ReadLog};
|
||||
use effectcraft_render::{EvalCtx, NoFootage, RenderOpts, Renderer};
|
||||
use effectcraft_time::Tick;
|
||||
|
||||
@@ -26,7 +29,8 @@ struct Sampled {
|
||||
type Key = (usize, u64, u64, u64, bool, u64);
|
||||
|
||||
thread_local! {
|
||||
static CACHE: RefCell<HashMap<Key, Option<Sampled>>> = RefCell::new(HashMap::new());
|
||||
/// The sampled buffers and the source files each was made of.
|
||||
static CACHE: RefCell<HashMap<Key, (Option<Sampled>, Arc<ReadFiles>)>> = RefCell::new(HashMap::new());
|
||||
/// Nested sampleImage renders (a sampled layer whose expressions sample again).
|
||||
static DEPTH: RefCell<usize> = const { RefCell::new(0) };
|
||||
}
|
||||
@@ -48,7 +52,13 @@ fn render(ctx: EvalCtx, comp: ItemId, layer: &Layer, post: bool, t: f64) -> Opti
|
||||
return None;
|
||||
}
|
||||
let key: Key = (ctx.project as *const _ as usize, comp.0, layer.id.0, t.to_bits(), post, fingerprint(layer));
|
||||
if let Some(hit) = CACHE.with(|c| c.borrow().get(&key).cloned()) {
|
||||
let note = |files: &ReadFiles| {
|
||||
if let Some(log) = ctx.reads {
|
||||
log.note_all(files);
|
||||
}
|
||||
};
|
||||
if let Some((hit, files)) = CACHE.with(|c| c.borrow().get(&key).cloned()) {
|
||||
note(&files);
|
||||
return hit;
|
||||
}
|
||||
DEPTH.with(|d| *d.borrow_mut() += 1);
|
||||
@@ -60,20 +70,24 @@ fn render(ctx: EvalCtx, comp: ItemId, layer: &Layer, post: bool, t: f64) -> Opti
|
||||
}
|
||||
let _pop = Pop;
|
||||
let footage: &dyn effectcraft_render::FootageSource = ctx.footage.unwrap_or(&NoFootage);
|
||||
let log = ReadLog::new();
|
||||
let mut r = Renderer::new(ctx.project, footage, RenderOpts { motion_blur: false, ..Default::default() });
|
||||
r.expr = ctx.expr;
|
||||
r.reads = Some(&log);
|
||||
let ectx = r.eval_ctx(comp, Tick::from_seconds_f64(t))?;
|
||||
let out = if post {
|
||||
r.content_buf(&ectx, layer).map(|b| Sampled { img: Arc::new(b.img.clone()), offset: b.offset, scale: b.scale })
|
||||
} else {
|
||||
r.layer_source(&ectx, layer).map(|b| Sampled { img: Arc::new(b.img), offset: b.offset, scale: b.scale })
|
||||
};
|
||||
let files = Arc::new(log.into_files());
|
||||
note(&files);
|
||||
CACHE.with(|c| {
|
||||
let mut c = c.borrow_mut();
|
||||
if c.len() >= MAX_CACHE {
|
||||
c.clear();
|
||||
}
|
||||
c.insert(key, out.clone());
|
||||
c.insert(key, (out.clone(), files));
|
||||
});
|
||||
out
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user