Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

Merge remote-tracking branch 'origin/main' into HEAD

bflatasticf3f9be4be34b
diff --cc crates/export/src/pipeline.rs
index 63200b40d,ae52d3478..856060039
--- a/crates/export/src/pipeline.rs
+++ b/crates/export/src/pipeline.rs
@@@ -262,13 -226,58 +280,59 @@@ impl<'a> Cx<'a>
}
return out;
}
- // The cap is for the GPU's memory: once it has stopped for good, frames render on the
- // CPU in parallel.
+ // The GPU cap is for the GPU's memory: once it has stopped for good, frames render on the
+ // CPU, in parallel or under the CPU cap (#1615), which holds throughout.
+ let caps = Inflight { gpu: self.gpu_cap(), cpu: cpu_inflight(std::env::var(CPU_INFLIGHT_ENV).ok().as_deref()) };
let gpu_live = || self.job.accel.is_none_or(|a| a.available());
- map_frames_while(ks, self.gpu_cap(), gpu_live, |k| self.frame(comp, k), f)
+ map_frames_while(ks, caps, gpu_live, |k| self.frame(comp, k), f)
}
+ /// [`Cx::frames`] for `ks` while `encode` runs beside them on `beside`'s threads, so the
+ /// render threads don't wait for the (largely sequential) encoder of the previous batch.
+ /// With deferred readbacks, or where no encode thread could be started, `encode` runs first.
+ #[cfg(test)]
+ pub async fn frames_beside<T: Send, A: Send>(
+ &self,
+ beside: &Beside,
+ comp: &Comp,
+ ks: Vec<u64>,
+ f: impl Fn(u64, Image) -> T + Sync + Send,
+ encode: impl FnOnce() -> A + Send,
+ ) -> crate::Result<(A, Vec<T>)> {
+ self.beside(beside, self.frames(comp, ks, f), encode).await
+ }
+
+ /// Run `encode` on `beside`'s threads while `frames` renders the next batch. With deferred
+ /// readbacks, or where no encode thread could be started, `encode` runs first.
+ pub async fn beside<T: Send, A: Send>(
+ &self,
+ beside: &Beside,
+ frames: impl std::future::Future<Output = Vec<T>>,
+ encode: impl FnOnce() -> A + Send,
+ ) -> crate::Result<(A, Vec<T>)> {
+ match &beside.0 {
+ Some(pool) if !self.deferred() => {
+ let mut done = None;
+ let frames = pool.in_place_scope(|s| {
+ s.spawn(|_| done = Some(std::panic::catch_unwind(std::panic::AssertUnwindSafe(encode))));
+ effectcraft_render::passes::block_on(frames)
+ });
+ match done {
+ Some(Ok(a)) => Ok((a, frames)),
+ Some(Err(panic)) => {
+ let why = panic.downcast_ref::<&str>().map(|s| s.to_string()).or_else(|| panic.downcast_ref::<String>().cloned()).unwrap_or_default();
+ Err(crate::ExportError::Encode(format!("the encoder stopped unexpectedly: {why}")))
+ }
+ None => Err(crate::ExportError::Encode("the encoder stopped unexpectedly".into())),
+ }
+ }
+ _ => {
+ let a = encode();
+ Ok((a, frames.await))
+ }
+ }
+ }
+
/// GPU frames rendered at once (#879), decided once per batch: with a GPU accelerator every
/// frame in flight holds its own working textures, so a whole batch rendered at once can
/// exhaust VRAM (or shared memory, which crashes instead of falling back). `None` when the