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
A page draw past Vello's buffers is painted again before its frame is encoded, in the fed render too
shinyobjectz087949140d70
diff --git a/bench/vello-skip/check.sh b/bench/vello-skip/check.shnew file mode 100755index 00000000..679d7007--- /dev/null+++ b/bench/vello-skip/check.sh@@ -0,0 +1,17 @@+#!/bin/bash+# A page whose first draw is past raea's Vello bump buffers (shards.tsx): the mp4's frame 0 must be the page, not black.+# The fed render (pages handed to raea-render) never checked its draws, so a skipped draw went into the film as it was:+# a black first frame, or a layer gone for a frame (#23). It now checks before the frame goes to the encoder and+# paints the page again at Vello's own sizes. Exits 1 on a failure.+# bench/vello-skip/check.sh (RAEA_BIN: the raea to run, default target/release/raea)+cd "$(dirname "$0")/../.." || exit 2+BIN=${RAEA_BIN:-$PWD/target/release/raea}+export RAEA_SIGN=0 RAEA_MARK=0 RAEA_EXPORT_CACHE=0+OUT=$(mktemp -d "${TMPDIR:-/tmp}/raea-vello-skip.XXXXXX")+trap 'rm -rf "$OUT"' EXIT+"$BIN" render bench/vello-skip/shards.tsx -o "$OUT/v.mp4" > "$OUT/v.log" 2>&1 || { echo "FAIL: the render failed"; tail -3 "$OUT/v.log"; exit 1; }+grep -q "past raea's Vello buffers" "$OUT/v.log" || echo "note: the first draw fit raea's buffers this time (nothing skipped to check)"+ffmpeg -loglevel error -y -i "$OUT/v.mp4" -frames:v 1 "$OUT/f0.png" || { echo "FAIL: no frame 0"; exit 1; }+mean=$(magick "$OUT/f0.png" -colorspace gray -format "%[fx:int(mean*255)]" info:)+[ "$mean" -ge 15 ] || { echo "FAIL: frame 0's mean luma is $mean: the skipped first draw went out (black is 0, the page about 22)"; exit 1; }+echo "PASS: a skipped first draw is painted again before it's encoded (frame 0's mean luma $mean)"diff --git a/bench/vello-skip/shards.tsx b/bench/vello-skip/shards.tsxnew file mode 100644index 00000000..a2799e14--- /dev/null+++ b/bench/vello-skip/shards.tsx@@ -0,0 +1,38 @@+// A page past raea's smaller Vello bump buffers on its first frame (70 clipped, 3D-transformed, blurred shards of a+// chrome block under a grain overlay at 1920 x 1080): Vello then draws nothing and says so only in a read back.++import { AbsoluteFill, Composition, registerRoot, useCurrentFrame } from "raea";++const rnd = (i: number, k: number) => { const s = Math.sin(i * 127.1 + k * 311.7) * 43758.5453; return s - Math.floor(s); };++function Chrome() {+ return (+ <div style={{ position: "absolute", left: 470, top: 214, width: 980, height: 640, borderRadius: 14, background: "linear-gradient(160deg, #3a4150, #1b1f27)", boxShadow: "0 30px 80px rgba(0,0,0,0.6)" }}>+ <div style={{ height: 46, background: "linear-gradient(#4a5160, #2c313b)", borderRadius: "14px 14px 0 0" }} />+ <div style={{ position: "absolute", left: 40, top: 90, width: 400, height: 24, background: "#8fa3c0", borderRadius: 6 }} />+ <div style={{ position: "absolute", left: 40, top: 140, width: 600, height: 300, background: "radial-gradient(circle at 30% 30%, #6b7fa0, #1e2533)", borderRadius: 10 }} />+ </div>+ );+}++function Scene() {+ const f = useCurrentFrame();+ const t = f / 30;+ const shards = Array.from({ length: 70 }, (_, i) => {+ const x = 470 + rnd(i, 1) * 980, y = 214 + rnd(i, 2) * 640;+ const pts = [0, 1, 2].map((k) => `${x + (rnd(i, k + 3) - 0.5) * 220}px ${y + (rnd(i, k + 6) - 0.5) * 220}px`).join(", ");+ const d = 0.5 + t;+ return (+ <div key={i} style={{ position: "absolute", inset: 0, clipPath: `polygon(${pts})`, transform: `perspective(1200px) translate3d(${(rnd(i, 9) - 0.5) * 900 * d}px, ${(rnd(i, 10) - 0.5) * 600 * d}px, ${rnd(i, 11) * 300 * d}px) rotateX(${rnd(i, 12) * 90 * d}deg) rotateY(${rnd(i, 13) * 90 * d}deg)`, filter: `blur(${1 + rnd(i, 14) * 2}px) brightness(${1 + rnd(i, 15) * 0.5})` }}>+ <Chrome />+ </div>+ );+ });+ return (+ <AbsoluteFill style={{ background: "#0b0d12", overflow: "hidden" }}>+ {shards}+ <AbsoluteFill style={{ opacity: 0.05, backgroundImage: "repeating-radial-gradient(circle at 17% 32%, #fff 0px, #000 2px, #fff 3px)", backgroundSize: "7px 7px" }} />+ </AbsoluteFill>+ );+}+registerRoot(() => <Composition id="shards" component={Scene} width={1920} height={1080} fps={30} durationInFrames={3} />);diff --git a/gpu/device/src/check.rs b/gpu/device/src/check.rsindex 9da4342b..07185d9f 100644--- a/gpu/device/src/check.rs+++ b/gpu/device/src/check.rs@@ -156,6 +156,26 @@ pub fn on_settle(settle: fn()) {let _ = SETTLE.set(settle);}+/// The fed render's frame `first`, checked before it goes to the encoder, where `skip_checked` could only draw the frames+/// after (a skipped first frame went out black): once `wait` (raea-page's `wait_drawn`) has every draw's read back+/// answered, a skipped draw has `paint` paint the frame again with Vello's own sizes; Err naming the frame when that's+/// skipped too (#23).+pub fn fed_checked<T>(f: i64, first: T, wait: fn(), redraw_full: fn(bool), paint: impl FnOnce() -> Result<T, String>) -> Result<T, String> {+ wait();+ if take_skipped().is_none() {+ return Ok(first);+ }+ redraw_full(true);+ let again = paint();+ redraw_full(false);+ let again = again?;+ wait();+ match take_skipped() {+ Some(why) => Err(format!("frame {f}: {why}")),+ None => Ok(again),+ }+}+fn take_skipped() -> Option<String> {if let Some(settle) = SETTLE.get() {settle();diff --git a/runtime/export/src/fed.rs b/runtime/export/src/fed.rsindex 30d2ac67..1ab59a67 100644--- a/runtime/export/src/fed.rs+++ b/runtime/export/src/fed.rs@@ -189,13 +189,11 @@ pub(crate) fn engine_before(app: &App, cx: &mut Ctx, f: i64) {#[allow(clippy::too_many_arguments)]pub(crate) fn render_fed(app: &mut App, js: &Path, w: u32, h: u32, fps: f64, total: i64, cx: &mut Ctx, out: &Path, work: &Path, wanted: &[i64], bevy: &mut raea_runtime_page::BevyPage) -> R<String> {let page = bevy_fed_buffer(w, h)?;- // the 3D made from the scene's rows beforehand (not a game's, stepped frame by frame): stepped again once a camera's- // box in the page is known+ // the 3D made from the scene's rows beforehand (not a game's): stepped again once a camera's box in the page is knownlet programmed = cx.scene3d.is_some() && cx.live3d.is_none();let mut restepped = false;let frames: std::cell::RefCell<Vec<(i64, Frame)>> = std::cell::RefCell::new(Vec::with_capacity(total.max(0) as usize));- // the sound is the one mixer core's bounce of the frames' sounds and notes, as live play mixes the same frames- // (raea-mixer)+ // the sound is the one mixer core's bounce of the frames' sounds and notes, as live play mixes them (raea-mixer)let notes: std::cell::RefCell<Vec<raea_sys_mix::ToneCue>> = std::cell::RefCell::new(Vec::new());let dir = cx.dir.to_path_buf();// the sound bounced as the frames come, on its own thread (it was mixed after the last frame: 3 s on the export)@@ -252,6 +250,8 @@ pub(crate) fn render_fed(app: &mut App, js: &Path, w: u32, h: u32, fps: f64, totfr = bevy_fed(app.world_mut(), bevy, cx, &page, fps)?;}}+ // a page draw past Vello's bump buffers, painted again at Vello's own sizes before the frame is encoded (#23)+ fr = raea_gpu_device::check::fed_checked(f, fr, raea_sys_page::wait_drawn, raea_sys_page::redraw_full, || { cx.manifest.as_mut().map(|m| m.pop()); bevy_fed(app.world_mut(), bevy, cx, &page, fps) })?;// a video's 3D made live keeps each frame's scene for the clipping checkif LIVE_CLIPS.load(std::sync::atomic::Ordering::Relaxed) { fr.scene = scene_of(app.world_mut()); }if cx.scene3d.is_none() && cx.live3d.is_none() && !cx.scene.is_empty() && BEVY_3D_PROBE.load(std::sync::atomic::Ordering::Relaxed) {diff --git a/systems/page/src/lib.rs b/systems/page/src/lib.rsindex ad84dfc7..a30c0d94 100644--- a/systems/page/src/lib.rs+++ b/systems/page/src/lib.rs@@ -18,6 +18,7 @@mod draw;mod skipped;+pub use skipped::wait_drawn;/// a page's loads (raea-sys-page-net: FileNet, FrameNet, the page's fetch, the image decoder)pub use raea_sys_page_net as net;pub use blitz_dom::not_applied; // what the page asked for and didn't get, said once when a render ends (#34)diff --git a/systems/page/src/skipped.rs b/systems/page/src/skipped.rsindex c7a46004..561f5d28 100644--- a/systems/page/src/skipped.rs+++ b/systems/page/src/skipped.rs@@ -30,6 +30,19 @@ pub fn settle() {}}+/// The last draw's sentinel read back, as submitted (`wait_drawn` waits for it).+static LAST: std::sync::Mutex<Option<wgpu::SubmissionIndex>> = std::sync::Mutex::new(None);++/// Every draw's read back answered, waiting for the last one: the fed render's check (export fed.rs), made before its+/// frame is handed to the encoder, since once encoded there's no frame left to draw again. It waits only for the page+/// draws the frame's composite waits for anyway.+pub fn wait_drawn() {+ let last = LAST.lock().unwrap_or_else(|e| e.into_inner()).take();+ if let (Some(d), Some(i)) = (DEVICE.get(), last) {+ let _ = d.poll(wgpu::PollType::Wait { submission_index: Some(i), timeout: None });+ }+}+/// `scene` drawn by Vello into `target` with `params`, its sentinel's read back on its way (`what` names it).pub fn render(renderer: &mut vello::Renderer, device: &wgpu::Device, queue: &wgpu::Queue, scene: &vello::Scene, target: &wgpu::Texture, params: &vello::RenderParams, what: &str) -> Result<(), String> {let check = std::env::var_os("RAEA_PAGE_DRAWN_CHECK").is_none_or(|v| v != "0");@@ -47,7 +60,7 @@ pub fn render(renderer: &mut vello::Renderer, device: &wgpu::Device, queue: &wgplet buf = device.create_buffer(&wgpu::BufferDescriptor { label: Some("raea-page drawn?"), size: 4, usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::MAP_READ, mapped_at_creation: false });let mut enc = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: Some("raea-page drawn?") });enc.copy_texture_to_buffer(texel, wgpu::TexelCopyBufferInfo { buffer: &buf, layout }, one);- queue.submit([enc.finish()]);+ *LAST.lock().unwrap_or_else(|e| e.into_inner()) = Some(queue.submit([enc.finish()]));let (read, what, (w, h)) = (buf.clone(), what.to_string(), (params.width, params.height));buf.slice(..).map_async(wgpu::MapMode::Read, move |r| {let skipped = r.is_ok() && read.slice(..).get_mapped_range().is_ok_and(|d| d[..4] == SENTINEL);