M4.14: content-keyed RAM preview frames; proxies in the disk cache's content key
- FrameKey's identity is the comp's content (frames::comp_content), not the project revision: an edit keeps the cached frames of comps it doesn't touch and undo finds the frames of the state it returns to. The identity hashes the addresses of the comps a comp draws (~0.1 ms on the 1500-layer test project; the full content hash took ~117 ms), by value the footage, solids, proxies and project settings; with expressions, every item. Frames::content_of keeps a project snapshot per identity with frames (or in flight), so Arc::make_mut always copies an edited comp and its address can't be reused meanwhile; past 64 identities the least recently used go with their frames (long drags). - drop_stale is gone (frames of other contents are evicted least-recently-shown first). - disk_cache::comp_content_key covers items' proxies and Use Proxy (it served stale frames). - Tests: frames (content keys, edits elsewhere and undo, bounded drags, in-place edit safety), ui_ram_preview (end to end), the disk cache proxy key. Docs: roadmap (M4 done), parity. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
4f7723a7b6
commit
26c714db7f
@@ -0,0 +1,53 @@
|
||||
//! RAM preview frames are keyed by content: editing one comp keeps the cached frames of another,
|
||||
//! and undo finds the frames of the state it returns to.
|
||||
|
||||
use effectcraft_engine::Session;
|
||||
use effectcraft_engine::project::ItemId;
|
||||
use effectcraft_ui_egui::EffectcraftApp;
|
||||
use egui_kittest::Harness;
|
||||
use serde_json::json;
|
||||
|
||||
fn settle(h: &mut Harness<'_, EffectcraftApp>) {
|
||||
for _ in 0..600 {
|
||||
h.step();
|
||||
if h.state().frames.inflight() == 0 && h.state().frames.last_ms.lock().map(|v| *v > 0.0).unwrap_or(false) {
|
||||
break;
|
||||
}
|
||||
std::thread::sleep(std::time::Duration::from_millis(10));
|
||||
}
|
||||
h.run_steps(2);
|
||||
}
|
||||
|
||||
fn shown_cached(h: &Harness<'_, EffectcraftApp>, comp: u64) -> bool {
|
||||
let app = h.state();
|
||||
let key = effectcraft_ui_egui::frames::FrameKey { frame: 0, ..app.shown_series(ItemId(comp)) };
|
||||
app.frames.is_cached(&key)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_edit_in_another_comp_keeps_the_cached_frames_and_undo_finds_them_again() {
|
||||
let mut s = Session::default();
|
||||
let b = s.execute("comp.new", json!({"name": "B", "width": 64, "height": 36, "duration": 1})).unwrap()["comp"].as_u64().unwrap();
|
||||
let a = s.execute("comp.new", json!({"name": "A", "width": 64, "height": 36, "duration": 1})).unwrap()["comp"].as_u64().unwrap();
|
||||
s.execute("layer.newSolid", json!({"color": "#3080ff"})).unwrap();
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(|_| EffectcraftApp::new(s));
|
||||
settle(&mut h);
|
||||
assert!(shown_cached(&h, a), "A's frame rendered");
|
||||
// Edit B (open it, add a layer), then come back to A: its frame is still in RAM.
|
||||
h.state_mut().session.execute("comp.open", json!({"comp": b})).unwrap();
|
||||
h.state_mut().session.execute("layer.newSolid", json!({"color": "#ff8030"})).unwrap();
|
||||
settle(&mut h);
|
||||
let b_frame = h.state().shown_series(ItemId(b));
|
||||
h.state_mut().session.execute("comp.open", json!({"comp": a})).unwrap();
|
||||
assert!(shown_cached(&h, a), "A's frame survived the edit in B");
|
||||
// Edit A, then undo: the frame of the state undo returns to is found again.
|
||||
let before = h.state().shown_series(ItemId(a));
|
||||
h.state_mut().session.execute("layer.newSolid", json!({"color": "#20c040"})).unwrap();
|
||||
settle(&mut h);
|
||||
assert_ne!(h.state().shown_series(ItemId(a)), before, "A's content changed");
|
||||
h.state_mut().session.execute("edit.undo", json!({})).unwrap();
|
||||
assert_eq!(h.state().shown_series(ItemId(a)), before);
|
||||
assert!(shown_cached(&h, a), "undo finds the earlier frame");
|
||||
// B's frame is still there too.
|
||||
assert!(h.state().frames.is_cached(&effectcraft_ui_egui::frames::FrameKey { frame: 0, ..b_frame }));
|
||||
}
|
||||
@@ -137,7 +137,15 @@ fn gpu_worker_renders_effect_frames_and_the_disk_cache_survives_a_reload() {
|
||||
s.execute("prop.set", json!({"layer": "#1", "path": "effects/#1/blurriness", "value": 12})).unwrap();
|
||||
let opts = RenderOpts { backend: effectcraft_engine::render::Backend::Gpu, ..Default::default() };
|
||||
let t = effectcraft_engine::time::Tick::ZERO;
|
||||
let key = |comp: effectcraft_engine::project::ItemId| FrameKey { revision: s.revision, comp: comp.0, frame: 0, scale: 1000, view: 0, opts: 0 };
|
||||
let key = |comp: effectcraft_engine::project::ItemId| FrameKey {
|
||||
revision: s.revision,
|
||||
content: effectcraft_ui_egui::frames::comp_content(&s.project, comp),
|
||||
comp: comp.0,
|
||||
frame: 0,
|
||||
scale: 1000,
|
||||
view: 0,
|
||||
opts: 0,
|
||||
};
|
||||
let disk = Arc::new(Mutex::new(HashMap::new()));
|
||||
let worker = Arc::new(GpuWorker::new(&s, worker_gpu.clone(), disk.clone()));
|
||||
let mut frames = Frames::default();
|
||||
|
||||
@@ -105,16 +105,24 @@ fn viewer_frames_render_remotely_from_project_diffs() {
|
||||
let comp = s.active_comp_id().unwrap();
|
||||
let c = s.project.comp(comp).unwrap().clone();
|
||||
let opts = RenderOpts { scale: 0.25, guides: true, ..Default::default() };
|
||||
let key = |rev: u64, f: i64| FrameKey { revision: rev, comp: comp.0, frame: f, scale: 250, view: 0, opts: 0 };
|
||||
let key = |s: &Session, f: i64| FrameKey {
|
||||
revision: s.revision,
|
||||
content: effectcraft_ui_egui::frames::comp_content(&s.project, comp),
|
||||
comp: comp.0,
|
||||
frame: f,
|
||||
scale: 250,
|
||||
view: 0,
|
||||
opts: 0,
|
||||
};
|
||||
let worker = Arc::new(FakeWorker::new(&s, 2));
|
||||
let mut frames = Frames::default();
|
||||
frames.set_remote(Some(worker.clone()));
|
||||
assert!(frames.remote_active());
|
||||
// Three prefetch frames, then the viewer's frame.
|
||||
for f in 1..=3 {
|
||||
frames.request(&source(&s), key(s.revision, f), comp, c.frame_rate.tick_of(f), opts);
|
||||
frames.request(&source(&s), key(&s, f), comp, c.frame_rate.tick_of(f), opts);
|
||||
}
|
||||
frames.request_urgent(&source(&s), key(s.revision, 10), comp, c.frame_rate.tick_of(10), opts);
|
||||
frames.request_urgent(&source(&s), key(&s, 10), comp, c.frame_rate.tick_of(10), opts);
|
||||
assert_eq!(frames.inflight(), 4);
|
||||
// Nothing renders until dispatched (no frame threads with a remote renderer); the viewer's
|
||||
// frame goes first, then prefetch in request order.
|
||||
@@ -126,15 +134,15 @@ fn viewer_frames_render_remotely_from_project_diffs() {
|
||||
// Frames arrive: the cache holds exactly what the page would have rendered.
|
||||
worker.deliver();
|
||||
assert_eq!(frames.remote_busy(), 0);
|
||||
let img = match frames.get(&key(s.revision, 10)).expect("viewer frame cached") {
|
||||
let img = match frames.get(&key(&s, 10)).expect("viewer frame cached") {
|
||||
FrameImage::Cpu(c) => c,
|
||||
FrameImage::Gpu(_) => unreachable!(),
|
||||
};
|
||||
let local = effectcraft_ui_egui::frames::to_color_image(&s.render(comp, c.frame_rate.tick_of(10), opts));
|
||||
assert_eq!(img.size, local.size);
|
||||
assert_eq!(img.pixels, local.pixels);
|
||||
assert!(frames.is_cached(&key(s.revision, 1)));
|
||||
assert!(!frames.is_cached(&key(s.revision, 2)));
|
||||
assert!(frames.is_cached(&key(&s, 1)));
|
||||
assert!(!frames.is_cached(&key(&s, 2)));
|
||||
// The rest; an edit later travels as a patch.
|
||||
frames.dispatch_remote();
|
||||
worker.deliver();
|
||||
@@ -142,19 +150,19 @@ fn viewer_frames_render_remotely_from_project_diffs() {
|
||||
worker.deliver();
|
||||
assert_eq!(frames.inflight(), 0);
|
||||
s.execute("layer.newSolid", json!({"color": "#ff8800"})).unwrap();
|
||||
frames.request_urgent(&source(&s), key(s.revision, 10), comp, c.frame_rate.tick_of(10), opts);
|
||||
frames.request_urgent(&source(&s), key(&s, 10), comp, c.frame_rate.tick_of(10), opts);
|
||||
frames.dispatch_remote();
|
||||
worker.deliver();
|
||||
assert_eq!(worker.syncs.lock().unwrap().last(), Some(&"patch"));
|
||||
let FrameImage::Cpu(img) = frames.get(&key(s.revision, 10)).unwrap() else { unreachable!() };
|
||||
let FrameImage::Cpu(img) = frames.get(&key(&s, 10)).unwrap() else { unreachable!() };
|
||||
let local = effectcraft_ui_egui::frames::to_color_image(&s.render(comp, c.frame_rate.tick_of(10), opts));
|
||||
assert_eq!(img.pixels, local.pixels);
|
||||
// A lost frame is released (requested again later), not cached.
|
||||
frames.request(&source(&s), key(s.revision, 20), comp, c.frame_rate.tick_of(20), opts);
|
||||
frames.request(&source(&s), key(&s, 20), comp, c.frame_rate.tick_of(20), opts);
|
||||
frames.dispatch_remote();
|
||||
worker.lose();
|
||||
assert_eq!(frames.inflight(), 0);
|
||||
assert!(!frames.is_cached(&key(s.revision, 20)));
|
||||
assert!(!frames.is_cached(&key(&s, 20)));
|
||||
// Without slots the remote renderer is unusable (frames render here again).
|
||||
frames.set_remote(Some(Arc::new(FakeWorker::new(&s, 0))));
|
||||
assert!(!frames.remote_active());
|
||||
|
||||
Reference in New Issue
Block a user