mirror of
https://github.com/storytold/effectcraft.git
synced 2026-12-02 15:01:26 -05:00
Render log says why a job renders on the CPU and names the GPU adapter (#3732)
* Render log: say why a GPU project renders on the CPU, and name the GPU adapter (#3727) * WebM: the header, the size patch and delivering the file count as writing time; last_timing says whose it is (#3732 review) * Export timing: label the initial compositor and attached GPU adapter, count frames that fell back to the CPU later The timing line says "Initial compositor" and "attached GPU adapter" for the choice made at the start. A frame asked of the GPU that ends with the GPU unavailable is counted in the new gpu_fallback_frames, and the line reports it as "Later GPU fallback: N of M frames rendered on the CPU after the GPU became unavailable". New test: a_gpu_lost_after_the_start_is_reported_apart_from_the_initial_choice. * Export timing: frames the probe drops do not count as a later GPU fallback A device lost while Auto measures makes the job pick the CPU and drop the GPU's measured frames, so only frames of a job that chose the GPU are counted. * Export timing: count a GPU fallback when the frame is rendered, not from the adapter afterwards The renderer now notes per frame whether the accelerator declined it while unavailable (Renderer::comp_frame_noting_gpu_loss, passes::comp_frame_noting_gpu_loss), and the export counts that. A frame the GPU rendered no longer counts when another frame in flight loses the device before it is counted. The test renders two frames at once: frame 0 on the GPU while frame 1 loses the device. * Deferred readbacks: a frame that goes to the CPU after missed passes says whether the device was lost in_passes records why it renders the frame without the accelerator (Passed::gpu_lost: the device is no longer available, not passes run out on a healthy one), and passes::comp_frame_noting_gpu_loss passes that on instead of dropping it with .value. New test: a_deferred_frame_on_the_cpu_says_whether_the_device_was_lost. --------- Co-authored-by: FredApps <FredApps@users.noreply.github.com>
This commit is contained in:
@@ -902,6 +902,9 @@ fn render(args: &Args, json_out: bool) -> Result<(), Failure> {
|
||||
return usage_err("render runs headless; use `exec renderQueue.add` / `renderQueue.render` with --bridge");
|
||||
}
|
||||
let mut s = session(args)?;
|
||||
if let Some(gpu) = &s.accel {
|
||||
note!("GPU adapter: {}", gpu.name());
|
||||
}
|
||||
if args.opt("--template").is_some() {
|
||||
template::prepare(&mut s, args)?;
|
||||
} else if let Some(p) = &args.project {
|
||||
|
||||
@@ -267,6 +267,9 @@ pub(crate) struct Cx<'a> {
|
||||
gpu_frames: Mutex<Option<(usize, String)>>,
|
||||
/// A frame has rendered on the GPU compositor: its memory can be measured.
|
||||
gpu_rendered: std::sync::atomic::AtomicBool,
|
||||
/// Frames asked of the GPU compositor that ended with the GPU unavailable: they fell back
|
||||
/// to the CPU after the job started.
|
||||
gpu_fallback_frames: std::sync::atomic::AtomicU64,
|
||||
/// Auto's CPU frames in flight once settled ([`Cx::auto_cpu_frames`]; `Some(None)`: not
|
||||
/// capped).
|
||||
cpu_frames: Mutex<Option<Option<usize>>>,
|
||||
@@ -404,6 +407,7 @@ impl<'a> Cx<'a> {
|
||||
choice: Mutex::new(None),
|
||||
gpu_frames: Mutex::new(None),
|
||||
gpu_rendered: Default::default(),
|
||||
gpu_fallback_frames: Default::default(),
|
||||
cpu_frames: Mutex::new(None),
|
||||
frame_times,
|
||||
overflowed: Mutex::new(vec![]),
|
||||
@@ -447,7 +451,8 @@ impl<'a> Cx<'a> {
|
||||
audio_seconds: self.phases.measured(Stage::Audio),
|
||||
frames,
|
||||
frames_per_second: if wall > 0.0 { frames as f64 / wall } else { 0.0 },
|
||||
renderer: self.choice().map_or_else(|| "none was needed".to_string(), |c| describe_choice(&c)),
|
||||
renderer: self.choice().map_or_else(|| "none was needed".to_string(), |c| self.describe(&c)),
|
||||
gpu_fallback_frames: self.gpu_fallback_frames.load(std::sync::atomic::Ordering::Relaxed),
|
||||
encoder: describe_encoder(self.job.output),
|
||||
}
|
||||
}
|
||||
@@ -463,7 +468,10 @@ impl<'a> Cx<'a> {
|
||||
fn fixed_choice(&self, env: Option<&str>) -> Option<Choice> {
|
||||
let fixed = |renderer, why| Some(Choice { renderer, gpu_ms: None, cpu_ms: None, why });
|
||||
if self.project_renderer() == crate::JobRenderer::Cpu {
|
||||
return fixed(crate::JobRenderer::Cpu, "the project's renderer");
|
||||
// A project that asks for the GPU but has no accelerator in this session (the headless
|
||||
// CLI without `--gpu`) renders on the CPU: say so, not "the project's renderer".
|
||||
let why = if self.project.settings.gpu_acceleration { "no GPU compositor is attached to this session" } else { "the project's renderer" };
|
||||
return fixed(crate::JobRenderer::Cpu, why);
|
||||
}
|
||||
if self.deferred() {
|
||||
return fixed(crate::JobRenderer::Gpu, "the project's renderer");
|
||||
@@ -505,7 +513,18 @@ impl<'a> Cx<'a> {
|
||||
});
|
||||
}
|
||||
}
|
||||
log::info!(target: "effectcraft_export", "{}: {}", self.job.options.label, describe_choice(&c));
|
||||
log::info!(target: "effectcraft_export", "{}: {}", self.job.options.label, self.describe(&c));
|
||||
}
|
||||
|
||||
/// [`describe_choice`] with the GPU adapter attached to a GPU project's job, so a log shows
|
||||
/// which device was measured. It describes the choice made at the start: a later fallback to
|
||||
/// the CPU is counted apart ([`Cx::timing`]).
|
||||
fn describe(&self, c: &Choice) -> String {
|
||||
let d = describe_choice(c);
|
||||
match self.job.accel {
|
||||
Some(a) if self.project.settings.gpu_acceleration => format!("{d}; attached GPU adapter: {}", a.name()),
|
||||
_ => d,
|
||||
}
|
||||
}
|
||||
|
||||
/// The job's choice, once made.
|
||||
@@ -562,9 +581,10 @@ impl<'a> Cx<'a> {
|
||||
r
|
||||
}
|
||||
|
||||
async fn render_at(&self, t: Tick, on: crate::JobRenderer) -> Image {
|
||||
/// A frame at `t`, and whether the CPU rendered it because the GPU was lost meanwhile.
|
||||
async fn render_at(&self, t: Tick, on: crate::JobRenderer) -> (Image, bool) {
|
||||
// With deferred GPU readbacks (a browser worker) the frame renders in passes.
|
||||
effectcraft_render::passes::comp_frame(&self.renderer_on(on), self.job.comp, t).await
|
||||
effectcraft_render::passes::comp_frame_noting_gpu_loss(&self.renderer_on(on), self.job.comp, t).await
|
||||
}
|
||||
|
||||
/// Whether frames render in passes (an accelerator with deferred readbacks).
|
||||
@@ -834,16 +854,27 @@ impl<'a> Cx<'a> {
|
||||
async fn frame_async_on(&self, comp: &Comp, i: u64, on: crate::JobRenderer) -> Image {
|
||||
let t0 = Instant::now();
|
||||
let gpu = on == crate::JobRenderer::Gpu && self.job.accel.is_some();
|
||||
let img = match self.job.settings.sample(comp, i) {
|
||||
let (img, lost) = match self.job.settings.sample(comp, i) {
|
||||
FrameSample::Progressive(t) => self.render_at(t, on).await,
|
||||
FrameSample::Fields { first, second, upper_first } => {
|
||||
let a = self.render_at(first, on).await;
|
||||
if second == first { a } else { interleave(&a, &self.render_at(second, on).await, upper_first) }
|
||||
let (a, lost) = self.render_at(first, on).await;
|
||||
if second == first {
|
||||
(a, lost)
|
||||
} else {
|
||||
let (b, lost_b) = self.render_at(second, on).await;
|
||||
(interleave(&a, &b, upper_first), lost || lost_b)
|
||||
}
|
||||
}
|
||||
};
|
||||
if gpu {
|
||||
self.gpu_rendered.store(true, std::sync::atomic::Ordering::Relaxed);
|
||||
}
|
||||
|
||||
// Counted as the frame was rendered; a probe that picks the CPU drops its GPU frames
|
||||
let chose_gpu = self.choice().is_some_and(|c| c.renderer == crate::JobRenderer::Gpu);
|
||||
if lost && chose_gpu {
|
||||
self.gpu_fallback_frames.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
|
||||
}
|
||||
let img = self.crop_resize(img);
|
||||
if let Some(ft) = &self.frame_times {
|
||||
ft.lock().unwrap_or_else(std::sync::PoisonError::into_inner).push((i, t0.elapsed().as_secs_f64()));
|
||||
@@ -1434,6 +1465,145 @@ mod tests {
|
||||
assert_eq!(Cx::new(&job).gpu_cap(), None, "no accelerator");
|
||||
}
|
||||
|
||||
/// #3706: a project that asks for the GPU but renders in a session without an accelerator (the
|
||||
/// headless CLI without `--gpu`) said "the project's renderer": the log gives the real reason.
|
||||
/// With an accelerator the log names the adapter.
|
||||
#[test]
|
||||
fn the_log_says_why_a_gpu_project_renders_on_the_cpu_and_on_which_adapter() {
|
||||
if std::env::var_os(RENDERER_ENV).is_some() {
|
||||
return;
|
||||
}
|
||||
use effectcraft_project::render_queue::{OutputFormat, OutputModule, RenderSettings};
|
||||
use effectcraft_render::NoFootage;
|
||||
let (settings, output) = (RenderSettings::default(), OutputModule::for_format(OutputFormat::PngSequence));
|
||||
let accel = NoAccel;
|
||||
let describe = |gpu: bool, with_accel: bool| {
|
||||
let mut p = Project::default();
|
||||
p.settings.gpu_acceleration = gpu;
|
||||
let job = Job {
|
||||
project: &p,
|
||||
footage: &NoFootage,
|
||||
expr: None,
|
||||
accel: if with_accel { Some(&accel) } else { None },
|
||||
comp: effectcraft_project::ItemId(0),
|
||||
settings: &settings,
|
||||
output: &output,
|
||||
path: "/c/f_[#####].png",
|
||||
sink: None,
|
||||
nested_switches: true,
|
||||
options: Default::default(),
|
||||
};
|
||||
let cx = Cx::new(&job);
|
||||
cx.choice().map(|c| cx.describe(&c))
|
||||
};
|
||||
assert_eq!(describe(true, false).as_deref(), Some("Software Rendering (no GPU compositor is attached to this session)"));
|
||||
assert_eq!(describe(false, true).as_deref(), Some("Software Rendering (the project's renderer)"));
|
||||
assert_eq!(describe(false, false).as_deref(), Some("Software Rendering (the project's renderer)"));
|
||||
// A GPU project with an accelerator measures first; the adapter shows once it chose.
|
||||
assert_eq!(describe(true, true), None);
|
||||
let mut p = Project::default();
|
||||
p.settings.gpu_acceleration = true;
|
||||
let job = Job {
|
||||
project: &p,
|
||||
footage: &NoFootage,
|
||||
expr: None,
|
||||
accel: Some(&accel),
|
||||
comp: effectcraft_project::ItemId(0),
|
||||
settings: &settings,
|
||||
output: &output,
|
||||
path: "/c/f_[#####].png",
|
||||
sink: None,
|
||||
nested_switches: true,
|
||||
options: Default::default(),
|
||||
};
|
||||
let cx = Cx::new(&job);
|
||||
cx.decide(Choice { renderer: crate::JobRenderer::Cpu, gpu_ms: Some(164.5), cpu_ms: Some(115.6), why: "measured on the first frames" });
|
||||
assert_eq!(
|
||||
cx.timing(1.0, 1).renderer,
|
||||
"Software Rendering (measured on the first frames: GPU 164.5 ms/frame, CPU 115.6 ms/frame); attached GPU adapter: none"
|
||||
);
|
||||
}
|
||||
|
||||
/// An accelerator that renders the frames before `gpu_until`, each only once another frame
|
||||
/// has lost the device, and loses the device on the first later frame (which falls back).
|
||||
struct LostWhileRendering {
|
||||
lost: AtomicBool,
|
||||
gpu_until: Tick,
|
||||
}
|
||||
impl effectcraft_render::Accelerator for LostWhileRendering {
|
||||
fn name(&self) -> String {
|
||||
"lost".into()
|
||||
}
|
||||
fn comp_frame(&self, _r: &Renderer, _comp: effectcraft_project::ItemId, t: Tick) -> Option<Image> {
|
||||
if t >= self.gpu_until {
|
||||
self.lost.store(true, Ordering::Relaxed);
|
||||
return None;
|
||||
}
|
||||
|
||||
// Bounded: with a single render thread the sibling never runs meanwhile
|
||||
let waited = Instant::now();
|
||||
while !self.lost.load(Ordering::Relaxed) && waited.elapsed().as_secs() < 10 {
|
||||
std::thread::yield_now();
|
||||
}
|
||||
Some(Image::new(16, 8))
|
||||
}
|
||||
fn supports_effect(&self, _id: &str) -> bool {
|
||||
false
|
||||
}
|
||||
fn effects(&self, _chain: &[effectcraft_render::FxStep], _buf: &effectcraft_effects::Buf, _levels: Option<f32>) -> Option<effectcraft_effects::Buf> {
|
||||
None
|
||||
}
|
||||
fn available(&self) -> bool {
|
||||
!self.lost.load(Ordering::Relaxed)
|
||||
}
|
||||
}
|
||||
|
||||
/// #3732 review: a GPU job whose device becomes unavailable after it started keeps its
|
||||
/// initial choice and attached adapter as such and reports the frames that fell back apart.
|
||||
/// Two frames are in flight: frame 0 renders on the GPU while frame 1 loses the device.
|
||||
#[test]
|
||||
fn a_gpu_lost_after_the_start_is_reported_apart_from_the_initial_choice() {
|
||||
use effectcraft_project::render_queue::{OutputFormat, OutputModule, RenderSettings};
|
||||
let (settings, output) = (RenderSettings::default(), OutputModule::for_format(OutputFormat::PngSequence));
|
||||
let mut p = Project::default();
|
||||
p.settings.gpu_acceleration = true;
|
||||
let comp = Comp::new(16, 8, effectcraft_time::FrameRate::FPS_25, Tick::from_seconds_f64(12.0 / 25.0));
|
||||
let cid = p.add_item("Comp", effectcraft_color::Label::Sandstone, None, effectcraft_project::ItemKind::Comp(comp.into()));
|
||||
let sink: &crate::Sink = &|_: &str, _: Vec<u8>| {};
|
||||
let export = |renderer: Option<Backend>, gpu_until: Tick| {
|
||||
let accel = LostWhileRendering { lost: AtomicBool::new(false), gpu_until };
|
||||
let shared = Mutex::new(renderer);
|
||||
let job = Job {
|
||||
project: &p,
|
||||
footage: &effectcraft_render::NoFootage,
|
||||
expr: None,
|
||||
accel: Some(&accel),
|
||||
comp: cid,
|
||||
settings: &settings,
|
||||
output: &output,
|
||||
path: "/l/f_[#####].png",
|
||||
sink: Some(sink),
|
||||
nested_switches: true,
|
||||
options: crate::JobOptions { renderer: Some(&shared), gpu_frames: Some(2), ..Default::default() },
|
||||
};
|
||||
crate::export(&job, &mut |_| true).expect("export").timing
|
||||
};
|
||||
|
||||
let chosen = export(Some(Backend::Gpu), Tick::from_seconds_f64(0.5 / 25.0));
|
||||
let measured = std::env::var_os(RENDERER_ENV).is_none().then(|| export(None, Tick(0)));
|
||||
|
||||
assert_eq!(chosen.renderer, "GPU Acceleration (as the queue item's first output module); attached GPU adapter: lost");
|
||||
assert_eq!((chosen.gpu_fallback_frames, chosen.frames), (11, 12), "frame 0 rendered on the GPU before the loss counted");
|
||||
let line = chosen.summary();
|
||||
assert!(line.contains("Initial compositor: GPU Acceleration"), "{line}");
|
||||
assert!(line.contains("Later GPU fallback: 11 of 12 frames rendered on the CPU after the GPU became unavailable"), "{line}");
|
||||
// Lost while Auto measures: the job picks the CPU and the GPU's measured frames are dropped
|
||||
if let Some(measured) = measured {
|
||||
assert!(measured.renderer.starts_with("Software Rendering (measured on the first frames"), "{}", measured.renderer);
|
||||
assert_eq!(measured.gpu_fallback_frames, 0, "{}", measured.summary());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_one_off_exports_caches_take_the_budget_it_is_given() {
|
||||
// #3941: a one-off export's own caches had 512 MiB each whatever the memory budget; the
|
||||
|
||||
@@ -57,9 +57,17 @@ fn a_movie_export_reports_where_the_time_went() {
|
||||
assert!(t.encoder.contains("H.264") && t.encoder.contains("software"), "{}", t.encoder);
|
||||
|
||||
let line = t.summary();
|
||||
for part in
|
||||
["export took", "30 frames", "frames/s", "overlap", "rendering frames", "encoder", "writing output", "Compositor: Software Rendering", "Encoder: H.264"]
|
||||
{
|
||||
for part in [
|
||||
"export took",
|
||||
"30 frames",
|
||||
"frames/s",
|
||||
"overlap",
|
||||
"rendering frames",
|
||||
"encoder",
|
||||
"writing output",
|
||||
"Initial compositor: Software Rendering",
|
||||
"Encoder: H.264",
|
||||
] {
|
||||
assert!(line.contains(part), "{part:?} missing from {line}");
|
||||
}
|
||||
// The render log carries the same line.
|
||||
@@ -115,6 +123,23 @@ fn gif_and_webm_time_the_stages_they_have() {
|
||||
assert!(e <= t.wall_seconds && w <= t.wall_seconds && t.render_seconds <= t.wall_seconds, "{t:?}");
|
||||
}
|
||||
|
||||
/// #3732 review: delivering the finished file is writing time in both WebM paths (VP9 and AV1):
|
||||
/// for a sink, a share or a slow disk it is where the time goes. The sink here takes 200 ms.
|
||||
#[test]
|
||||
fn a_slow_sink_counts_as_writing_time_in_both_webm_paths() {
|
||||
use effectcraft_export::render_queue::WebmVideoCodec;
|
||||
let (p, cid) = project();
|
||||
let settings = RenderSettings { time_span: TimeSpan::LengthOfComp, ..Default::default() };
|
||||
let sink: &Sink = &|_: &str, _: Vec<u8>| std::thread::sleep(std::time::Duration::from_millis(200));
|
||||
for codec in [WebmVideoCodec::Vp9, WebmVideoCodec::Av1] {
|
||||
let mut webm = OutputModule::for_format(OutputFormat::WebM);
|
||||
webm.webm_codec = codec;
|
||||
let t = export(&job_of(&p, cid, &settings, &webm, "/out/slow.webm", sink), &mut |_| true).expect("webm").timing;
|
||||
let write = t.write_seconds.expect("write time");
|
||||
assert!(write >= 0.19, "{codec:?}: the sink's 200 ms are writing time, got {write} s");
|
||||
}
|
||||
}
|
||||
|
||||
/// #3724 review: a failed export's render log carries the timing line too (with the compositor
|
||||
/// that ran), not only a finished one's.
|
||||
#[test]
|
||||
@@ -189,11 +214,14 @@ fn a_stopped_export_has_a_summary_without_a_frame_count() {
|
||||
let t = effectcraft_export::render_queue::RenderTiming {
|
||||
wall_seconds: 2.0,
|
||||
render_seconds: 1.5,
|
||||
renderer: "Software Rendering (x)".into(),
|
||||
renderer: "GPU Acceleration (x)".into(),
|
||||
gpu_fallback_frames: 3,
|
||||
encoder: "H.264".into(),
|
||||
..Default::default()
|
||||
};
|
||||
let line = t.summary_of_unfinished("stopped");
|
||||
assert!(line.starts_with("export stopped after 2.00 s. Busy time per stage"), "{line}");
|
||||
assert!(!line.contains("frames/s"), "{line}");
|
||||
// (#3732 review) the frames that fell back are counted without a total the stop doesn't know
|
||||
assert!(line.contains("Later GPU fallback: 3 frames rendered on the CPU after the GPU became unavailable"), "{line}");
|
||||
}
|
||||
|
||||
@@ -1500,8 +1500,13 @@ pub struct RenderTiming {
|
||||
pub frames: u64,
|
||||
/// Frames per second of wall time over the whole job.
|
||||
pub frames_per_second: f64,
|
||||
/// The compositor and why it was used.
|
||||
/// The compositor chosen when the job started, why, and the GPU adapter attached then. Frames
|
||||
/// that later fell back to the CPU are counted in `gpu_fallback_frames`, not in this label.
|
||||
pub renderer: String,
|
||||
/// Frames asked of the GPU compositor that fell back to the CPU because the GPU became
|
||||
/// unavailable after the job started (0: none).
|
||||
#[serde(skip_serializing_if = "is_zero")]
|
||||
pub gpu_fallback_frames: u64,
|
||||
/// The encoder: name, software or hardware, codec settings.
|
||||
pub encoder: String,
|
||||
}
|
||||
@@ -1539,10 +1544,22 @@ impl RenderTiming {
|
||||
}
|
||||
}
|
||||
let stages = s;
|
||||
format!("{head}. Busy time per stage (the stages overlap, so this is not a sum): {stages}. Compositor: {}. Encoder: {}", self.renderer, self.encoder)
|
||||
let fallback = match (self.gpu_fallback_frames, self.frames) {
|
||||
(0, _) => String::new(),
|
||||
(n, 0) => format!(". Later GPU fallback: {n} frames rendered on the CPU after the GPU became unavailable"),
|
||||
(n, m) => format!(". Later GPU fallback: {n} of {m} frames rendered on the CPU after the GPU became unavailable"),
|
||||
};
|
||||
format!(
|
||||
"{head}. Busy time per stage (the stages overlap, so this is not a sum): {stages}. Initial compositor: {}{fallback}. Encoder: {}",
|
||||
self.renderer, self.encoder
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn is_zero(n: &u64) -> bool {
|
||||
*n == 0
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct RenderQueueItem {
|
||||
/// Stable id (unique within the queue).
|
||||
@@ -1565,7 +1582,8 @@ pub struct RenderQueueItem {
|
||||
/// Resolved path of the last render (first file for sequences).
|
||||
#[serde(default)]
|
||||
pub last_output: Option<String>,
|
||||
/// Where the last render's time went (see [`RenderTiming`]).
|
||||
/// Where the last render's time went (see [`RenderTiming`]): of the first Output Module's
|
||||
/// export; the item's own Render Time covers all of its Output Modules.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub last_timing: Option<RenderTiming>,
|
||||
/// Further Output Modules (Composition ▸ Add Output Module): the same frames are encoded
|
||||
|
||||
@@ -29,6 +29,9 @@ pub struct Passed<T> {
|
||||
pub passes: u32,
|
||||
/// Rendered with the accelerator (not the CPU fallback after [`MAX_PASSES`]).
|
||||
pub accelerated: bool,
|
||||
/// The CPU fallback ran because the accelerator was no longer available (its device was
|
||||
/// lost), not because the passes ran out on a healthy device.
|
||||
pub gpu_lost: bool,
|
||||
}
|
||||
|
||||
/// Whether `accel` defers its readbacks (renders take passes).
|
||||
@@ -42,21 +45,23 @@ pub fn is_deferred(accel: Option<&dyn Accelerator>) -> bool {
|
||||
/// ([`crate::LayerCache::set_gate`]).
|
||||
pub async fn in_passes<'a, T>(accel: Option<&'a dyn Accelerator>, mut render: impl FnMut(Option<&'a dyn Accelerator>) -> T) -> Passed<T> {
|
||||
let Some(a) = accel.filter(|a| a.miss_gate().is_some()) else {
|
||||
return Passed { value: render(accel), passes: 1, accelerated: accel.is_some() };
|
||||
return Passed { value: render(accel), passes: 1, accelerated: accel.is_some(), gpu_lost: false };
|
||||
};
|
||||
a.frame_begin();
|
||||
for pass in 1..=MAX_PASSES {
|
||||
a.pass_begin();
|
||||
let value = render(Some(a));
|
||||
if !a.pass_missed() {
|
||||
return Passed { value, passes: pass, accelerated: true };
|
||||
return Passed { value, passes: pass, accelerated: true, gpu_lost: false };
|
||||
}
|
||||
match a.settle() {
|
||||
Some(s) => s.await,
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
Passed { value: render(None), passes: MAX_PASSES + 1, accelerated: false }
|
||||
// Why the frame goes to the CPU, decided here: a lost device, or passes run out on a healthy one
|
||||
let gpu_lost = !a.available();
|
||||
Passed { value: render(None), passes: MAX_PASSES + 1, accelerated: false, gpu_lost }
|
||||
}
|
||||
|
||||
/// Ends the frame for the accelerator ([`Accelerator::frame_end`]) when dropped: also when the
|
||||
@@ -73,10 +78,16 @@ impl Drop for FrameEnd<'_> {
|
||||
/// frame workers do. Ends the frame for the accelerator ([`Accelerator::frame_end`]) on every
|
||||
/// exit, including a panic.
|
||||
pub async fn comp_frame(r: &Renderer<'_>, comp: ItemId, t: Tick) -> Image {
|
||||
let Some(a) = r.accel else { return r.comp_frame(comp, t) };
|
||||
comp_frame_noting_gpu_loss(r, comp, t).await.0
|
||||
}
|
||||
|
||||
/// [`comp_frame`], and whether the CPU rendered it because the accelerator was lost
|
||||
/// ([`Renderer::comp_frame_noting_gpu_loss`]).
|
||||
pub async fn comp_frame_noting_gpu_loss(r: &Renderer<'_>, comp: ItemId, t: Tick) -> (Image, bool) {
|
||||
let Some(a) = r.accel else { return r.comp_frame_noting_gpu_loss(comp, t) };
|
||||
let _end = FrameEnd(a);
|
||||
if a.miss_gate().is_none() {
|
||||
return r.comp_frame(comp, t);
|
||||
return r.comp_frame_noting_gpu_loss(comp, t);
|
||||
}
|
||||
let mut opts = r.opts;
|
||||
let mut auto = None;
|
||||
@@ -94,9 +105,11 @@ pub async fn comp_frame(r: &Renderer<'_>, comp: ItemId, t: Tick) -> Image {
|
||||
}
|
||||
let t0 = web_time::Instant::now();
|
||||
let img = if opts.backend == Backend::Cpu {
|
||||
Renderer { opts, accel: None, ..*r }.comp_frame(comp, t)
|
||||
(Renderer { opts, accel: None, ..*r }.comp_frame(comp, t), false)
|
||||
} else {
|
||||
in_passes(Some(a), |acc| Renderer { opts, accel: acc, ..*r }.comp_frame(comp, t)).await.value
|
||||
let passed = in_passes(Some(a), |acc| Renderer { opts, accel: acc, ..*r }.comp_frame_noting_gpu_loss(comp, t)).await;
|
||||
let (img, lost) = passed.value;
|
||||
(img, lost || passed.gpu_lost)
|
||||
};
|
||||
if let Some(t) = auto {
|
||||
t.record(t0.elapsed().as_secs_f64() * 1e3);
|
||||
|
||||
@@ -615,7 +615,22 @@ impl<'a> Renderer<'a> {
|
||||
/// Render a composition at comp time `t` (transparent background, comp size × scale).
|
||||
/// Top-level frames go to the GPU when [`Self::active_accel`] is set and handles them.
|
||||
pub fn comp_frame(&self, comp_id: ItemId, t: Tick) -> Image {
|
||||
self.comp_frame_with(comp_id, t, false, |a| Ok::<_, std::convert::Infallible>(a.comp_frame(self, comp_id, t))).unwrap_or_else(|never| match never {})
|
||||
self.comp_frame_noting_gpu_loss(comp_id, t).0
|
||||
}
|
||||
|
||||
/// [`Self::comp_frame`], and whether the CPU rendered it because the accelerator declined it
|
||||
/// while no longer [available](Accelerator::available). Decided when the accelerator answers:
|
||||
/// a frame it rendered never counts, whatever another frame does to the device afterwards.
|
||||
pub fn comp_frame_noting_gpu_loss(&self, comp_id: ItemId, t: Tick) -> (Image, bool) {
|
||||
let lost = std::cell::Cell::new(false);
|
||||
let img = self
|
||||
.comp_frame_with(comp_id, t, false, |a| {
|
||||
let img = a.comp_frame(self, comp_id, t);
|
||||
lost.set(img.is_none() && !a.available());
|
||||
Ok::<_, std::convert::Infallible>(img)
|
||||
})
|
||||
.unwrap_or_else(|never| match never {});
|
||||
(img, lost.get())
|
||||
}
|
||||
|
||||
/// Render a frame, validating the accelerated attempt before starting any CPU fallback.
|
||||
|
||||
@@ -1113,6 +1113,56 @@ fn comp_frame_ends_the_frame_when_the_render_panics() {
|
||||
assert_eq!(a.ends.load(Ordering::SeqCst), 1);
|
||||
}
|
||||
|
||||
/// Deferred readbacks whose every pass misses: a lost device can't settle them any more.
|
||||
struct MissingAccel {
|
||||
lost: std::sync::atomic::AtomicBool,
|
||||
gate: std::sync::Arc<std::sync::atomic::AtomicBool>,
|
||||
}
|
||||
impl crate::Accelerator for MissingAccel {
|
||||
fn name(&self) -> String {
|
||||
"missing".into()
|
||||
}
|
||||
fn comp_frame(&self, _r: &crate::Renderer, _comp: ItemId, _t: Tick) -> Option<crate::Image> {
|
||||
Some(crate::Image::new(1, 1))
|
||||
}
|
||||
fn supports_effect(&self, _id: &str) -> bool {
|
||||
false
|
||||
}
|
||||
fn effects(&self, _chain: &[crate::FxStep], _buf: &crate::Buf, _levels: Option<f32>) -> Option<crate::Buf> {
|
||||
None
|
||||
}
|
||||
fn available(&self) -> bool {
|
||||
!self.lost.load(std::sync::atomic::Ordering::SeqCst)
|
||||
}
|
||||
fn pass_missed(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn miss_gate(&self) -> Option<std::sync::Arc<std::sync::atomic::AtomicBool>> {
|
||||
Some(self.gate.clone())
|
||||
}
|
||||
fn settle(&self) -> Option<std::pin::Pin<Box<dyn std::future::Future<Output = ()> + '_>>> {
|
||||
(!self.lost.load(std::sync::atomic::Ordering::SeqCst)).then(|| Box::pin(std::future::ready(())) as _)
|
||||
}
|
||||
}
|
||||
|
||||
/// #3732 review: a deferred frame that goes to the CPU says whether a lost device sent it
|
||||
/// there, apart from passes that ran out on a healthy device.
|
||||
#[test]
|
||||
fn a_deferred_frame_on_the_cpu_says_whether_the_device_was_lost() {
|
||||
let (mut p, cid, comp) = setup();
|
||||
let l = solid(&mut p, &comp, [1.0, 0.0, 0.0], 50, 50);
|
||||
p.comp_mut(cid).unwrap().layers.push(l);
|
||||
let frame = |lost: bool| {
|
||||
let a = MissingAccel { lost: lost.into(), gate: Default::default() };
|
||||
let mut r = crate::Renderer::new(&p, &crate::NoFootage, crate::RenderOpts { backend: crate::Backend::Gpu, ..Default::default() });
|
||||
r.accel = Some(&a);
|
||||
crate::passes::block_on(crate::passes::comp_frame_noting_gpu_loss(&r, cid, Tick::ZERO)).1
|
||||
};
|
||||
|
||||
assert!(frame(true), "a lost device's frame fell back");
|
||||
assert!(!frame(false), "passes that ran out on a healthy device are no device loss");
|
||||
}
|
||||
|
||||
/// The renderer labels Project Settings ▸ Video Rendering and Effects draws parse back as the
|
||||
/// backend they name (in any case), and the older spellings still work.
|
||||
#[test]
|
||||
|
||||
+3
-2
@@ -122,8 +122,9 @@ Commands (CLI, MCP, control channel):
|
||||
gets it as a `Timing:` line when its Log setting writes a log for that outcome (under the
|
||||
default Errors Only, failed jobs only; a failed job's line says how long it ran and what ran
|
||||
before it stopped): the wall time, the busy time of rendering, the encoder and writing the file
|
||||
(the stages overlap, so they are not a sum), the compositor and why, the encoder and its
|
||||
settings, and frames per second ([#3713](https://github.com/storytold/effectcraft/issues/3713)).
|
||||
(the stages overlap, so they are not a sum), the compositor chosen at the start and why (with
|
||||
the attached GPU adapter), how many frames fell back to the CPU when the GPU became unavailable
|
||||
later, the encoder and its settings, and frames per second ([#3713](https://github.com/storytold/effectcraft/issues/3713)).
|
||||
`effectcraft-cli render --json` returns it as `timing` and `timingSummary`.
|
||||
- `threeD.defaultRenderer`: Default 3D Renderer
|
||||
- `labels.N.name` / `labels.N.color`: the 16 label names and colours, used by the Label menu,
|
||||
|
||||
Reference in New Issue
Block a user