Export: a Render Queue job renders every frame on the project's renderer (#414)

Cause: pipeline::Cx rendered with Backend::Auto, which picks the CPU or the
GPU compositor for each top-level frame from measured frame times
(render::AutoPick: warm-up on both sides, a re-probe every 48 frames). The
two compositors differ slightly, so frames came out differently depending
on which side the timings favoured in that run, and two GPU exports of the
same frames differed.

Fix: the job renders every frame on the project's renderer, as After
Effects renders a job with one renderer: Backend::Gpu with Mercury GPU
Acceleration (frames the GPU declines still render on the CPU, as they do
in every GPU render), Backend::Cpu with Mercury Software Only. The viewer
and previews keep Auto. Docs (architecture, parity, web) say so.

Tests: render_settings::a_job_renders_on_one_compositor exports ten frames
with a stand-in GPU compositor that keeps Auto history and draws solid
green: with Mercury GPU Acceleration every frame is green and two runs are
identical (with Auto the warm-up sent frames to the CPU: it fails), with
Software Only the stand-in is never asked. The web worker GPU job test's
comment no longer describes Auto.

Diagnosis by @pat-the-wizard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bflatastic
2026-10-09 22:26:17 +07:00
co-authored by Claude Opus 5.5
parent 1ccf7cb910
commit 8c4a3cbfe0
9 changed files with 96 additions and 12 deletions
+1
View File
@@ -31,6 +31,7 @@ log = { workspace = true }
[dev-dependencies]
effectcraft-media = { workspace = true }
effectcraft-effects = { workspace = true }
effectcraft-color = { workspace = true }
filmcraft-opus = { workspace = true }
filmcraft-vp9 = { workspace = true }
+2 -1
View File
@@ -75,7 +75,8 @@ pub struct Job<'a> {
pub project: &'a Project,
pub footage: &'a dyn FootageSource,
pub expr: Option<&'a dyn ExprHost>,
/// GPU compositor: used when the project's renderer is Mercury GPU Acceleration.
/// GPU compositor: used for every frame of the job when the project's renderer is Mercury
/// GPU Acceleration (frames it declines render on the CPU).
pub accel: Option<&'a dyn effectcraft_render::Accelerator>,
pub comp: ItemId,
pub settings: &'a RenderSettings,
+6 -2
View File
@@ -9,7 +9,7 @@ use effectcraft_project::render_queue::{
};
use effectcraft_project::{Comp, Project};
use effectcraft_raster::Image;
use effectcraft_render::{LayerCache, RenderOpts, Renderer};
use effectcraft_render::{Backend, LayerCache, RenderOpts, Renderer};
use effectcraft_time::Tick;
use web_time::Instant;
@@ -87,6 +87,10 @@ impl<'a> Cx<'a> {
/// and layer cache.
fn renderer(&self) -> Renderer<'_> {
let s = self.job.settings;
// The whole job renders on the project's renderer (Mercury GPU Acceleration or Software
// Only), not on whichever compositor Auto timed faster for each frame: the CPU and GPU
// compositors differ slightly, so a per-frame choice made renders differ run to run.
let backend = if self.project.settings.gpu_acceleration { Backend::Gpu } else { Backend::Cpu };
let opts = RenderOpts {
scale: s.resolution.clamp(0.01, 4.0),
motion_blur: s.motion_blur_override() != SwitchOverride::OffForAll,
@@ -94,7 +98,7 @@ impl<'a> Cx<'a> {
draft: s.quality == RenderQuality::Draft,
// Output renders always look through the comp's active camera.
view: None,
backend: effectcraft_render::Backend::Auto,
backend,
roi: None,
nested_switches: self.job.nested_switches,
draft_shadows: true,
+77 -3
View File
@@ -1,16 +1,18 @@
//! Render Settings and Output Module features end to end (through a [`Sink`], so nothing touches
//! the disk): field rendering and 3:2 pulldown, crop / region of interest / resize, alpha-only
//! and premultiplied output, the solo and guide-layer overrides, the render log, storage
//! overflow and PCM audio formats.
//! overflow, PCM audio formats and the compositor a job renders on.
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Arc, Mutex};
use effectcraft_color::Label;
use effectcraft_effects::Buf;
use effectcraft_export::render_queue::*;
use effectcraft_export::{Job, JobOptions, Report, Sink, StorageQuota, export};
use effectcraft_keyframe::{Keyframe, Value};
use effectcraft_project::{Comp, ItemId, ItemKind, LayerSource, Project, Solid, build};
use effectcraft_render::NoFootage;
use effectcraft_render::{Accelerator, AutoPick, FxStep, Image, NoFootage, Renderer};
use effectcraft_time::{FrameRate, Tick};
const W: u32 = 64;
@@ -43,6 +45,20 @@ fn custom(start: f64, end: f64) -> RenderSettings {
}
fn run_with(p: &Project, cid: ItemId, s: &RenderSettings, om: &OutputModule, path: &str, options: JobOptions, cancel: bool) -> (Result<Report, String>, Files) {
run_on(p, cid, s, om, path, options, None, cancel)
}
/// [`run_with`] with an accelerator.
fn run_on(
p: &Project,
cid: ItemId,
s: &RenderSettings,
om: &OutputModule,
path: &str,
options: JobOptions,
accel: Option<&dyn Accelerator>,
cancel: bool,
) -> (Result<Report, String>, Files) {
let files: Files = Default::default();
let f = files.clone();
let sink: Box<Sink> = Box::new(move |path: &str, data: Vec<u8>| f.lock().unwrap().push((path.to_string(), data)));
@@ -50,7 +66,7 @@ fn run_with(p: &Project, cid: ItemId, s: &RenderSettings, om: &OutputModule, pat
project: p,
footage: &NoFootage,
expr: None,
accel: None,
accel,
comp: cid,
settings: s,
output: om,
@@ -402,3 +418,61 @@ fn cancelled_export_removes_only_files_it_opened() {
}
std::fs::remove_dir_all(dir).unwrap();
}
/// A GPU compositor stand-in that renders every frame solid green (the CPU draws the bar and the
/// block on black) and keeps Auto's timing history.
#[derive(Default)]
struct GreenAccel {
pick: AutoPick,
frames: AtomicUsize,
}
impl Accelerator for GreenAccel {
fn name(&self) -> String {
"green".into()
}
fn comp_frame(&self, r: &Renderer, comp: ItemId, _t: Tick) -> Option<Image> {
self.frames.fetch_add(1, Ordering::SeqCst);
let c = r.project.comp(comp)?;
Some(Image::filled(c.width, c.height, [0.0, 1.0, 0.0, 1.0]))
}
fn supports_effect(&self, _id: &str) -> bool {
false
}
fn effects(&self, _chain: &[FxStep], _buf: &Buf, _levels: Option<f32>) -> Option<Buf> {
None
}
fn auto_pick(&self) -> Option<&AutoPick> {
Some(&self.pick)
}
}
#[test]
fn a_job_renders_on_one_compositor() {
// #414: Auto chose the CPU or the GPU for each frame from measured frame times, so GPU
// renders of the same frames differed run to run. A job renders every frame on the
// project's renderer.
let (mut p, cid) = project(FrameRate::new(25, 1), |_, _| {});
let om = OutputModule::for_format(OutputFormat::PngSequence);
let s = custom(0.0, 0.4);
let render = |p: &Project, accel: &GreenAccel, path: &str| {
let (r, files) = run_on(p, cid, &s, &om, path, JobOptions::default(), Some(accel), false);
r.expect("export");
(0..10).map(|i| png(&files, i)).collect::<Vec<_>>()
};
// Mercury GPU Acceleration: every frame on the GPU, the same in every run.
p.settings.gpu_acceleration = true;
let gpu = GreenAccel::default();
let a = render(&p, &gpu, "/g/a_[#####].png");
assert_eq!(gpu.frames.load(Ordering::SeqCst), 10);
for (i, f) in a.iter().enumerate() {
assert!(f.pixels().all(|px| px.0 == [0, 255, 0, 255]), "frame {i} rendered on the CPU");
}
assert_eq!(a, render(&p, &gpu, "/g/b_[#####].png"));
// Mercury Software Only: every frame on the CPU.
p.settings.gpu_acceleration = false;
let cpu = GreenAccel::default();
let c = render(&p, &cpu, "/g/c_[#####].png");
assert_eq!(cpu.frames.load(Ordering::SeqCst), 0);
assert_eq!(c[0].get_pixel(10, 44).0, [255, 0, 0, 255], "the CPU drew the red block");
}