Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
SG4a: a long render's end checks let each scene, and then the solids, go
shinyobjectze8eafcdedb22
diff --git a/docs/stage-guards.feature b/docs/stage-guards.featureindex b2f0dde2..0c86e940 100644--- a/docs/stage-guards.feature+++ b/docs/stage-guards.feature@@ -159,7 +159,9 @@ Feature: Stage guards: a 3D render an agent can't break| raea-runtime-export | runtime/export/src/render.rs | +12 | a still past frame 3,600 made live (LIVE_PAST); stills keep their scenes for the end checks || raea-sys-stage | systems/stage/src/manifest.rs | +8 | the remounts counted as the frames go, not all at once || raea-core-scene | core/scene/src/lib.rs | +30 | spans_of: each part over the frames it's in; tracks_of built on it |- | raea-sys-contact | systems/contact/src/lib.rs | 0 | the clipping check over spans |+ | raea-sys-contact | systems/contact/src/lib.rs | 0 | the clipping check over spans; each pair's stretches kept as they come |+ | raea-sys-contact | systems/contact/src/model.rs | +12 | forget: the files' triangles and the parts' solids let go |+ | raea-runtime-export | runtime/export/src/scene.rs | +18 | told_taking: each frame's scene let go as its parts are made; forget and the memory marks after each end step |Then a 13,000-frame 3D render's memory stays within 10% of its first minute's# Status 11-21 (branch stage-guards-8): the film (13,175 frames, 7:19) renders whole with every end check on, at# a 9.4 to 13.6 GB peak. Before, memguard killed it past 24 GB (28 to 33 GB) after its last frame. Four causes,@@ -174,6 +176,14 @@ Feature: Stage guards: a 3D render an agent can't break# out, on either route (the live route ran none before: a game's stills were never staged). Not met: memory# still grows with the frames (about 2 GB at the first minute, 5.7 GB at the last frame), because each frame's# scene is kept for the end checks. Flat needs the checks to run over a window as the frames come.+ # Branch stage-guards-13: RAEA_MEM_MARKS=1 prints the footprint every RAEA_MEM_MARKS_EVERY frames of a live render+ # and after each end step. On the film: 1.2 GB at frame 0, 3.5 GB at 2000, 5.0 GB at 13000; 3.9 GB with each+ # frame's parts made (each scene let go as its parts are: about 1 GB); 7.6 GB after the clipping check, whose+ # solids (one per model file or shape expression, kept for the process) were still held while frame purity+ # rendered its stills; 3.3 GB once the end checks let them and the parts go. The render's peak fell from 10.5-10.9+ # GB to 9.3 GB, its 435 errors, 699 warns and 47 notes the same (the clipping check's in order; it keeps each+ # pair's stretches as they come, not every frame's hit). Still not met: memory grows by about 40% after the first+ # minute (the kept scenes), and the solids of every part are made at once, 3.8 GB on the film.Rule: The SDK stops allowing it@@ -344,9 +354,10 @@ Feature: Stage guards: a 3D render an agent can't break# data-allow-overlap may sit on any part (the manifest marks them allowOverlap): a headline across a card is an# error, the same words under data-allow-overlap pass. Stay (approved), rendered whole with its page known: two# errors, both meant, 'turn' drawn over the plant at 0:49 and the end title 'JUST THAT.' across the screen at- # 1:20; each takes data-allow-overlap (Stay already fails on its dolly reversal at 1:12, SG13). Left: `raea scene- # stage` doesn't know the page, since it draws none; the 3D guide's rule 9 doesn't name type-over-part yet (the- # guide's copy in the skills goes with a raea-skills change).+ # 1:20; each takes data-allow-overlap (Stay already fails on its dolly reversal at 1:12, SG13). Branch+ # stage-guards-12: the 3D guide's rule 9 and the skill's 3D router name type-over-part and data-allow-overlap+ # (raea-skills #112). Branch stage-guards-13: the findings are said in the order they start (a HashMap's order+ # changed from run to run). Left: `raea scene stage` doesn't know the page, since it draws none.Scenario: SG12. Nothing snapsGiven the plandiff --git a/runtime/export/src/fed.rs b/runtime/export/src/fed.rsindex 528e0343..dd0057ce 100644--- a/runtime/export/src/fed.rs+++ b/runtime/export/src/fed.rs@@ -288,6 +288,9 @@ pub(crate) fn render_fed(app: &mut App, js: &Path, w: u32, h: u32, fps: f64, tot}notes.borrow_mut().push(tone);frames.borrow_mut().push((f, fr));+ if f as usize % raea_render::engine::mark_every() == 0 {+ raea_render::engine::mem_mark(&format!("frame {f}"));+ }Ok(page.clone())},|| {@@ -326,7 +329,7 @@ pub(crate) fn render_fed(app: &mut App, js: &Path, w: u32, h: u32, fps: f64, totlet n = frames.borrow().len();// 3D parts passing through each other on screen: on stderr, and in the manifest for the legacy app's checkslet found = FED_CLIPPING.lock().unwrap().take().and_then(|t| t.join().ok());- let clipping = found.unwrap_or_else(|| scene::told(&frames.borrow(), cx.manifest.as_deref(), w, h, fps));+ let clipping = found.unwrap_or_else(|| scene::told_taking(&mut frames.borrow_mut(), cx.manifest.as_deref(), w, h, fps));write_manifest(cx, (w, h, fps, total), clipping, |cx| heard(&frames.borrow(), ¬es.borrow(), cx, fps))?;let ms = t0.elapsed().as_secs_f64() * 1e3 / n.max(1) as f64;Ok(format!("APPLIED {n} frames rendered to {} ({ms:.1} ms a frame, pages handed to raea-render on the GPU)", out.display()))diff --git a/runtime/export/src/render.rs b/runtime/export/src/render.rsindex 6bb11b4b..5fc51694 100644--- a/runtime/export/src/render.rs+++ b/runtime/export/src/render.rs@@ -352,7 +352,7 @@ pub(crate) fn render_bundle_with(js: &Path, dir: &Path, out: &Path, wanted: Opti}// with --manifest, its file as a 2D render writes it (it wrote none, and an older one stayed looking current, #28)drop(FED_CLIPPING.lock().unwrap().take());- let clipping = scene::told(&kept, cx.manifest.as_deref(), w, h, fps);+ let clipping = scene::told_taking(&mut kept, cx.manifest.as_deref(), w, h, fps);write_manifest(&mut cx, (w, h, fps, total), clipping, |_| json!([]))?;return Ok(if folder {format!("APPLIED {} frames rendered to {} (bevy_ui, the page over its 3D)", wanted.len(), out.display())diff --git a/runtime/export/src/run.rs b/runtime/export/src/run.rsindex 2ddfc1ec..da92c026 100644--- a/runtime/export/src/run.rs+++ b/runtime/export/src/run.rs@@ -110,8 +110,8 @@ pub(crate) fn scene_program_checked(js: &Path, dir: &Path, upto: i64, wanted: Opunsafe impl Send for Prepassed {}let owned = Prepassed(frames);*FED_CLIPPING.lock().unwrap() = Some(std::thread::spawn(move || {- let o = owned;- scene::told(&o.0, None, w, h, fps)+ let mut o = owned;+ scene::told_taking(&mut o.0, None, w, h, fps)}));Ok(Some(p))}diff --git a/runtime/export/src/scene.rs b/runtime/export/src/scene.rsindex 5e1858e3..3a0274e1 100644--- a/runtime/export/src/scene.rs+++ b/runtime/export/src/scene.rs@@ -18,13 +18,32 @@ pub fn all_items(frames: &[(i64, Frame)]) -> Vec<Vec<raea_core_scene::Item>> {/// it), and raea_sys_stage::told, the staging (RAEA_STAGE_CHECK=0), each said on stderr. `page` is the manifest's/// frames (each one's words in the page, which the staging holds off the parts: SG11), None where they aren't known.pub(crate) fn told(frames: &[(i64, Frame)], page: Option<&[serde_json::Value]>, w: u32, h: u32, fps: f64) -> Vec<raea_core_facts::Finding> {- if frames.iter().all(|(_, f)| f.scene.is_empty()) {+ checked(frames.iter().map(|(n, f)| (*n, raea_runtime_scene::items_of(&f.scene))).collect(), page, w, h, fps)+}++/// told for frames nothing reads the 3D of after: each frame's scene let go as its parts are made, so the end checks+/// don't hold every frame's scene and every frame's parts at once (SG4a)+pub(crate) fn told_taking(frames: &mut [(i64, Frame)], page: Option<&[serde_json::Value]>, w: u32, h: u32, fps: f64) -> Vec<raea_core_facts::Finding> {+ checked(frames.iter_mut().map(|(n, f)| (*n, raea_runtime_scene::items_of(&std::mem::take(&mut f.scene)))).collect(), page, w, h, fps)+}++fn checked(frames: Vec<(i64, Vec<raea_core_scene::Item>)>, page: Option<&[serde_json::Value]>, w: u32, h: u32, fps: f64) -> Vec<raea_core_facts::Finding> {+ if frames.iter().all(|(_, its)| its.is_empty()) {return Vec::new();}- let (nums, all): (Vec<i64>, _) = (frames.iter().map(|(f, _)| *f).collect(), all_items(frames));+ // RAEA_MEM_MARKS: the footprint after each end step (raea-render's mem_mark)+ let mark = raea_render::engine::mem_mark;+ mark("end checks: each frame's parts made");+ let (nums, all): (Vec<i64>, Vec<_>) = frames.into_iter().unzip();*SEEN.lock().unwrap() = Some(raea_sys_stage::seen(&all, &nums, w, h));let mut found = if std::env::var("RAEA_CLIP_CHECK").as_deref() == Ok("0") { Vec::new() } else { raea_sys_contact::told(&all, &nums, w, h, fps) };+ mark("end checks: clipping");found.extend(raea_sys_stage::told(&all, &nums, &page.map_or_else(Vec::new, |p| raea_sys_stage::pages(p, &nums)), w, h, fps));+ mark("end checks: staging");+ // the clipping check's solids, kept for the process, aren't needed again by a render+ raea_sys_contact::forget();+ drop(all);+ mark("end checks: done, their parts and solids let go");found}diff --git a/systems/contact/src/lib.rs b/systems/contact/src/lib.rsindex d72a4a97..c6de5dba 100644--- a/systems/contact/src/lib.rs+++ b/systems/contact/src/lib.rs@@ -32,7 +32,7 @@ mod found;pub use found::{clip_findings, lint_findings};mod model;-pub use model::{bounds, facing, seat_facing};+pub use model::{bounds, facing, forget, seat_facing};mod solid;use solid::*;@@ -276,7 +276,8 @@ pub fn check(all: &[Vec<Item>], frames: &[i64], w: u32, h: u32, fps: f64) -> Vec// frame by frame: the parts' world boxes swept along x for the pairs that meet, each pair's test reused while// neither part moves (the camera may still have)let mut last: HashMap<(usize, usize), (Mat4, Mat4, Option<Hit>)> = HashMap::new();- let mut found: HashMap<(usize, usize), Vec<(usize, Hit)>> = HashMap::new();+ // each pair's shown stretches (frames in a row) as they come: first, last, and the deepest hit (seam let go)+ let mut found: HashMap<(usize, usize), Vec<(usize, usize, (usize, Hit))>> = HashMap::new();// overlaps no frame shows (off frame, behind something): first and last frame, and the first frame's hitlet mut hidden: HashMap<(usize, usize), (usize, usize, Hit)> = HashMap::new();for k in 0..frames.len() {@@ -326,11 +327,19 @@ pub fn check(all: &[Vec<Item>], frames: &[i64], w: u32, h: u32, fps: f64) -> Vec}};last.insert((i, j), (wa, wb, r.clone()));- if let Some(hit) = r {+ if let Some(mut hit) = r {let (sa, sb) = (&a[hit.pieces.0], &b[hit.pieces.1]);let skip = 3.0 * (sa.cell * scale_of(&wa)).max(sb.cell * scale_of(&wb));- if shows(&all[k], &hit.seam, occ.get_or_insert_with(|| occluders(k)), skip, w as f32, h as f32) {- found.entry((i, j)).or_default().push((k, hit));+ if shows(&all[k], &std::mem::take(&mut hit.seam), occ.get_or_insert_with(|| occluders(k)), skip, w as f32, h as f32) {+ let runs = found.entry((i, j)).or_default();+ match runs.last_mut() {+ Some(run) if run.1 + 1 == k => {+ run.1 = k;+ // the deepest, the last of equals (as max_by took it)+ if hit.depth >= run.2.1.depth { run.2 = (k, hit) }+ }+ _ => runs.push((k, k, (k, hit))),+ }} else {hidden.entry((i, j)).or_insert((k, k, hit)).1 = k;}@@ -341,7 +350,7 @@ pub fn check(all: &[Vec<Item>], frames: &[i64], w: u32, h: u32, fps: f64) -> Vec// unseen on every frame: still said, so a clip turned away from reads as hidden, not fixed (DR3, DR9's cheats)let mut unseen: Vec<_> = hidden.into_iter().filter(|(p, _)| !found.contains_key(p)).collect();unseen.sort_by_key(|(p, (k, _, _))| (*k, *p));- let mut spans: Vec<((usize, usize), Vec<(usize, Hit)>)> = found.into_iter().collect();+ let mut spans: Vec<_> = found.into_iter().collect();spans.sort_by_key(|(p, g)| (g[0].0, *p));let clock = |f: i64| {let s = f as f64 / fps;@@ -364,18 +373,9 @@ pub fn check(all: &[Vec<Item>], frames: &[i64], w: u32, h: u32, fps: f64) -> Vec);out.push(json!({"from": f0, "to": f1, "part": small, "into": big, "depth": (hit.depth * 1000.0).round() / 1000.0, "share": (hit.share * 1000.0).round() / 1000.0, "move": {"axis": axis_name, "by": (step * 1000.0).round() / 1000.0}, "seen": seen, "says": says}));};- for ((i, j), got) in spans {- // a stretch is rendered frames in a row- let mut runs: Vec<Vec<&(usize, Hit)>> = Vec::new();- for g in &got {- match runs.last_mut() {- Some(r) if r.last().unwrap().0 + 1 == g.0 => r.push(g),- _ => runs.push(vec![g]),- }- }- for run in runs {- let &&(k, ref hit) = run.iter().max_by(|x, y| x.1.depth.total_cmp(&y.1.depth)).unwrap();- say(i, j, k, hit, frames[run.first().unwrap().0], frames[run.last().unwrap().0], true);+ for ((i, j), runs) in spans {+ for (first, last, (k, hit)) in runs {+ say(i, j, k, &hit, frames[first], frames[last], true);}}for ((i, j), (k0, k1, hit)) in unseen {diff --git a/systems/contact/src/model.rs b/systems/contact/src/model.rsindex be55d1e3..88e5f7aa 100644--- a/systems/contact/src/model.rs+++ b/systems/contact/src/model.rs@@ -8,9 +8,20 @@ use serde_json::{Value, json};use raea_core_scene::{gltf_tris, local};-/// A glTF file's triangles in its own space (its node transforms applied), read once a process.+/// Each glTF file's triangles, read once until [`forget`]+static CACHE: OnceLock<Mutex<HashMap<String, Result<Arc<Vec<Vec3>>, String>>>> = OnceLock::new();++/// Lets go of every file's triangles and every part's solids this process made, which a long render's clipping check+/// held to its end: on a 7-minute film, gigabytes still held while frame purity rendered its stills (SG4a).+pub fn forget() {+ if let Some(c) = CACHE.get() {+ c.lock().unwrap().clear();+ }+ crate::solid::forget_solids();+}++/// A glTF file's triangles in its own space (its node transforms applied), read once until [`forget`].pub fn file_tris(path: &str) -> Result<Arc<Vec<Vec3>>, String> {- static CACHE: OnceLock<Mutex<HashMap<String, Result<Arc<Vec<Vec3>>, String>>>> = OnceLock::new();if let Some(t) = CACHE.get_or_init(Default::default).lock().unwrap().get(path) {return t.clone();}diff --git a/systems/contact/src/solid.rs b/systems/contact/src/solid.rsindex 5ca64a38..e01c9aa8 100644--- a/systems/contact/src/solid.rs+++ b/systems/contact/src/solid.rs@@ -195,10 +195,19 @@ pub(crate) fn grid(tris: &[[Vec3; 3]], lo: Vec3, hi: Vec3, cell: f32) -> Solid {Solid { name: String::new(), min, cell, n, depth, inside, surf: Vec::new(), fine: None, lo, hi }}+/// Each file's or shape expression's solids, made once until [`crate::forget`]+static CACHE: OnceLock<Mutex<HashMap<String, Result<Arc<Vec<Solid>>, String>>>> = OnceLock::new();++/// Lets every made solid go (crate::forget).+pub(crate) fn forget_solids() {+ if let Some(c) = CACHE.get() {+ c.lock().unwrap().clear();+ }+}+/// A part's solids (one per mesh node of a model), made once per file or shape expression this process (an Err: not/// checked, and why).pub(crate) fn solid_of(it: &Item) -> Result<Arc<Vec<Solid>>, String> {- static CACHE: OnceLock<Mutex<HashMap<String, Result<Arc<Vec<Solid>>, String>>>> = OnceLock::new();let key = match it.kind {"model" => format!("model:{}", src_path(it.props.get("src").and_then(Value::as_str).unwrap_or(""))),_ => format!("mesh:{}", it.shape.as_deref().unwrap_or("")),diff --git a/systems/stage/src/page.rs b/systems/stage/src/page.rsindex 043f225f..fd153aac 100644--- a/systems/stage/src/page.rs+++ b/systems/stage/src/page.rs@@ -69,6 +69,9 @@ pub(crate) fn check(st: &Stage, page: &[Page]) -> Vec<Finding> {}}}+ // said in the order they start (a HashMap's order changed from run to run)+ let mut over: Vec<_> = over.into_iter().collect();+ over.sort_by_key(|(text, at)| (at.keys().min().copied(), text.clone()));let mut out = Vec::new();for (text, at) in over {for (a, b) in runs(st, st.all.len(), |k| at.contains_key(&k)) {