M12.1: render cache + parallel compositing fast paths
- render: LayerCache (content-keyed processed-layer cache: source -> masks -> effects, keyed by a hash of the layer's non-transform props evaluated at the frame time, solid item, switches, scale; time folded in for clock-driven effects / wiggle paths). Static and transform-only layers render once; edits only re-render the edited layer. Session + UI frame jobs share it. - effects: TIME_DEPENDENT list + test that every clock-reading effect is listed. - raster: affine composite fast path (per-row span clipping, unchecked interior bilinear, integer-translation copies, inlined Normal blend), checked against composite_warp_reference; box/Gaussian blur without transposes, two ping-pong buffers; accumulate_warp so motion blur sums into one buffer instead of one full-frame image per sub-sample. - ui: viewer frame is urgent and jumps the prefetch queue; stale-revision jobs are dropped; paused prefetch waits for the viewer frame; "Frame Render Time" reports viewer frames only; parallel f32 -> Color32 conversion. - cli: `frame --bench N` (per-layer/per-effect timings, wall + CPU time) and `frame --bench-play N` (consecutive frames with/without the layer cache). - tests: cache transparency (scrub, edits of values/keys/effects/masks/ solids/text/timing), hit/miss accounting, time-dependent effects, demo cached == uncached, fast warp/blur/accumulate == reference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
dee16181fe
commit
a2ff724ac2
@@ -16,7 +16,7 @@ use std::sync::Arc;
|
||||
|
||||
use effectcraft_project::{Comp, ItemId, Layer, LayerId, Project, Uid};
|
||||
use effectcraft_raster::Image;
|
||||
use effectcraft_render::{ExprHost, FootageSource, NoFootage, RenderOpts, Renderer};
|
||||
use effectcraft_render::{ExprHost, FootageSource, LayerCache, NoFootage, RenderOpts, Renderer};
|
||||
use effectcraft_time::Tick;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
@@ -135,6 +135,8 @@ pub struct Session {
|
||||
pub events: Vec<Event>,
|
||||
/// Commands executed: (id, params).
|
||||
pub journal: Vec<(String, Value)>,
|
||||
/// Processed-layer pixels reused across frames and edits (content-keyed, never stale).
|
||||
pub layer_cache: Arc<LayerCache>,
|
||||
}
|
||||
|
||||
impl Default for Session {
|
||||
@@ -152,6 +154,7 @@ impl Default for Session {
|
||||
importer: None,
|
||||
events: vec![],
|
||||
journal: vec![],
|
||||
layer_cache: Arc::new(LayerCache::default()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -303,6 +306,7 @@ impl Session {
|
||||
pub fn render(&self, comp: ItemId, t: Tick, opts: RenderOpts) -> Image {
|
||||
let mut r = Renderer::new(&self.project, self.footage.as_ref(), opts);
|
||||
r.expr = self.expr.as_deref();
|
||||
r.cache = Some(&self.layer_cache);
|
||||
r.comp_frame(comp, t)
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,35 @@ fn demo_opens_and_renders() {
|
||||
assert!(lit > 100_000, "{lit}");
|
||||
}
|
||||
|
||||
/// The session's layer cache never changes pixels: scrubbing the demo (including back and
|
||||
/// forth, and across an edit made through a command) matches cache-less renders exactly.
|
||||
#[test]
|
||||
fn demo_layer_cache_is_transparent() {
|
||||
let mut s = demo();
|
||||
let cid = s.active_comp_id().unwrap();
|
||||
let opts = effectcraft_render::RenderOpts { scale: 0.25, ..Default::default() };
|
||||
let uncached = |s: &Session, t: f64| {
|
||||
let mut r = effectcraft_render::Renderer::new(&s.project, s.footage.as_ref(), opts);
|
||||
r.expr = s.expr.as_deref();
|
||||
r.comp_frame(cid, effectcraft_time::Tick::from_seconds_f64(t))
|
||||
};
|
||||
let check = |s: &Session, t: f64| {
|
||||
let a = s.render(cid, effectcraft_time::Tick::from_seconds_f64(t), opts);
|
||||
let b = uncached(s, t);
|
||||
assert!(a.data.iter().zip(&b.data).all(|(p, q)| (0..4).all(|c| (p[c] - q[c]).abs() < 1e-6)), "t={t}");
|
||||
};
|
||||
for t in [0.5, 1.0, 3.0, 3.0334, 6.0, 3.0, 0.5] {
|
||||
check(&s, t);
|
||||
}
|
||||
assert!(s.layer_cache.stats().hits > 0);
|
||||
// Edit the title's glow through the command layer, then scrub again.
|
||||
let title = s.project.comp(cid).unwrap().layers.iter().find(|l| l.name == "EFFECTCRAFT").map(|l| l.id.0).unwrap();
|
||||
s.execute("prop.set", json!({"layer": title, "path": "effects/#1/radius", "value": 5.0})).unwrap();
|
||||
for t in [3.0, 0.5] {
|
||||
check(&s, t);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_command_has_unique_id_and_runs_or_reports() {
|
||||
let mut ids = std::collections::HashSet::new();
|
||||
|
||||
Reference in New Issue
Block a user