2026-10-02 10:59:08 -04:00
|
|
|
//! The EffectCraft GPU compositor (Mercury GPU Acceleration's counterpart), on wgpu compute
|
|
|
|
|
//! shaders: Metal, Vulkan, Direct3D 12 and WebGPU.
|
|
|
|
|
//!
|
|
|
|
|
//! The CPU [`Renderer`] stays the reference and keeps rendering layer *content* (sources, masks,
|
|
|
|
|
//! CPU effects, layer styles) into its layer cache. [`Gpu`] composites: it uploads the cached
|
|
|
|
|
//! layer buffers (once per buffer), applies the layer transforms with the CPU's sampling
|
|
|
|
|
//! (nearest / bilinear / bicubic, minification pre-filter), motion-blur sub-samples, track
|
|
|
|
|
//! mattes, Preserve Transparency, layer styles' passes, all 38 blend modes and the 8/16 bpc
|
2026-10-03 03:00:29 -04:00
|
|
|
//! clamping and quantisation, and converts colour spaces. Classic 3D runs composite here too
|
|
|
|
|
//! (`classic3d`: per-pixel fragment sort, lights, ray-cast shadows), and adjustment layers run
|
2026-10-03 09:38:11 -04:00
|
|
|
//! their effect stacks on the GPU-resident comp. Wireframe-quality outlines are drawn here too.
|
2026-10-02 10:59:08 -04:00
|
|
|
//!
|
2026-10-02 21:27:59 -04:00
|
|
|
//! Advanced 3D comps rasterise on a render pipeline (`advanced3d.wgsl`: depth buffer, PBR,
|
2026-10-03 09:38:11 -04:00
|
|
|
//! image-based light, shadow maps) and finish in compute kernels (`adv3d.wgsl`: supersampling
|
|
|
|
|
//! resolve, motion-blur sub-samples, iris depth of field, encoding, compositing), see
|
2026-10-03 18:26:06 -04:00
|
|
|
//! [`Accelerator::render_3d`] and `Renderer::prepare_adv_run`. Runs with layers on the 2D
|
|
|
|
|
//! compositing path (blend modes, track mattes, Preserve Transparency:
|
|
|
|
|
//! `Renderer::split_adv_run`) render each such layer alone, hide it behind the nearer main
|
|
|
|
|
//! scene and composite it through the 2D path here too; environment backgrounds (Classic and
|
|
|
|
|
//! Advanced 3D) draw their sky in a kernel (`Renderer::sky_draw`).
|
2026-10-02 21:27:59 -04:00
|
|
|
//!
|
2026-10-02 10:59:08 -04:00
|
|
|
//! GPU effects ([`effectcraft_effects::GPU_EFFECTS`]) run as compute kernels with the CPU
|
|
|
|
|
//! effect's exact steps (padding, box-blur radii, parameter conversions); chains of them are
|
2026-10-03 08:57:33 -04:00
|
|
|
//! uploaded and read back once. Each family lives in its own module with its own WGSL file
|
M13.28: GPU generators (fx_gen2): Lightning, Advanced Lightning, Beam, Lens Flare, Radio Waves, Vegas, Stroke, Scribble, Write-on, Paint Bucket, Eyedropper Fill, CC Glue Gun, CC Threads, Audio Spectrum/Waveform, Basic Text, Path Text
2026-10-04 02:56:00 -04:00
|
|
|
//! (`fx_color`, `fx_depth`, `fx_distort`, `fx_extra`, `fx_gen2`, `fx_generate`, `fx_key`,
|
2026-10-04 02:57:55 -04:00
|
|
|
//! `fx_light`, `fx_lut`, `fx_noise`, `fx_particles`, `fx_pixel2`, `fx_sim`, `fx_stylize`,
|
|
|
|
|
//! `fx_text`, `fx_time`, `fx_tone`, `fx_transition`, `fx_vr`, `fx_warp`); settings a kernel
|
|
|
|
|
//! cannot match fall back to the CPU (`catalog::gpu_supported`, or `None` from the family's
|
|
|
|
|
//! `apply`).
|
2026-10-03 18:36:26 -04:00
|
|
|
//! The 3D Channel effects read the layer's aux channels as an extra texture (`fx_depth`), the
|
|
|
|
|
//! colour-management effects interpret colour programs built next to the CPU effects
|
M13.28: GPU generators (fx_gen2): Lightning, Advanced Lightning, Beam, Lens Flare, Radio Waves, Vegas, Stroke, Scribble, Write-on, Paint Bucket, Eyedropper Fill, CC Glue Gun, CC Threads, Audio Spectrum/Waveform, Basic Text, Path Text
2026-10-04 02:56:00 -04:00
|
|
|
//! (`fx_lut`), simulations keep their state on the CPU and rasterise its per-frame plan here
|
2026-10-04 02:57:55 -04:00
|
|
|
//! (`fx_sim`, `fx_particles`), and so do the geometry generators (`fx_gen2`: bolts, strokes,
|
|
|
|
|
//! glyphs, audio marks, waves).
|
2026-10-03 10:53:00 -04:00
|
|
|
//!
|
|
|
|
|
//! Working textures come from a pool (`context::Pool`): a frame allocates several full-frame
|
|
|
|
|
//! RGBA f32 images per layer, and creating and zeroing those cost more than compositing a small
|
|
|
|
|
//! layer. A released texture is reused once every encoder that could still read it has been
|
|
|
|
|
//! submitted. 8/16 bpc quantisation after each layer is fused into that layer's composite.
|
|
|
|
|
//! [`Backend::Auto`](effectcraft_render::Backend) renders each comp on whichever compositor
|
|
|
|
|
//! measured faster for it ([`effectcraft_render::AutoPick`], kept by [`Gpu`]): a light comp
|
|
|
|
|
//! that the CPU composites in a millisecond stays there rather than paying for a full-frame
|
|
|
|
|
//! readback.
|
2026-10-02 10:59:08 -04:00
|
|
|
//!
|
2026-10-03 03:00:29 -04:00
|
|
|
//! GPU particles (`particles`): the stepped particle effects hand their simulation to
|
|
|
|
|
//! [`effectcraft_effects::psim::ParticleSim`], implemented here with one invocation per particle
|
|
|
|
|
//! and GPU-resident checkpoints.
|
|
|
|
|
//!
|
2026-10-02 10:59:08 -04:00
|
|
|
//! Plug a [`Gpu`] into [`Renderer::accel`] (it implements [`Accelerator`]); renders then use it
|
|
|
|
|
//! when [`RenderOpts::backend`](effectcraft_render::RenderOpts) asks for it. The viewer can
|
|
|
|
|
//! skip readback entirely with [`Gpu::render_display`], which leaves an RGBA8 texture for
|
|
|
|
|
//! egui-wgpu to draw.
|
|
|
|
|
|
2026-10-04 14:20:37 -04:00
|
|
|
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]
|
|
|
|
|
|
2026-10-02 21:27:59 -04:00
|
|
|
mod adv3d;
|
2026-10-03 07:44:43 -04:00
|
|
|
mod bokeh;
|
2026-10-03 02:15:01 -04:00
|
|
|
mod classic3d;
|
2026-10-02 10:59:08 -04:00
|
|
|
mod context;
|
2026-10-03 18:35:03 -04:00
|
|
|
pub mod deferred;
|
2026-10-02 10:59:08 -04:00
|
|
|
mod effects;
|
2026-10-03 02:25:12 -04:00
|
|
|
mod fx_color;
|
2026-10-03 17:33:41 -04:00
|
|
|
mod fx_depth;
|
2026-10-03 02:25:12 -04:00
|
|
|
mod fx_distort;
|
2026-10-03 10:53:00 -04:00
|
|
|
mod fx_extra;
|
M13.28: GPU generators (fx_gen2): Lightning, Advanced Lightning, Beam, Lens Flare, Radio Waves, Vegas, Stroke, Scribble, Write-on, Paint Bucket, Eyedropper Fill, CC Glue Gun, CC Threads, Audio Spectrum/Waveform, Basic Text, Path Text
2026-10-04 02:56:00 -04:00
|
|
|
mod fx_gen2;
|
2026-10-03 02:25:12 -04:00
|
|
|
mod fx_generate;
|
2026-10-03 07:51:33 -04:00
|
|
|
mod fx_key;
|
2026-10-03 17:31:26 -04:00
|
|
|
mod fx_light;
|
2026-10-03 17:43:24 -04:00
|
|
|
mod fx_lut;
|
2026-10-03 07:51:33 -04:00
|
|
|
mod fx_noise;
|
2026-10-04 01:35:56 -04:00
|
|
|
mod fx_particles;
|
M13.28: GPU pixel ports (fx_pixel2): CC Cross/Radial/Vector Blur, Reduce Interlace Flicker, CC Composite, Color Link, Cineon, HDR Compander/Highlight Compression, Grow Bounds, CC Overbrights, CC Block Load, CC Burn Film, CC Glass/Plastic, CC HexTile, CC Mr. Smoothie, Inner/Outer Key, CC Simple Wire Removal, Basic 3D
2026-10-04 01:33:54 -04:00
|
|
|
mod fx_pixel2;
|
2026-10-03 18:35:22 -04:00
|
|
|
mod fx_sim;
|
2026-10-03 07:51:33 -04:00
|
|
|
mod fx_stylize;
|
M13.22: GPU transitions and perspective (Block Dissolve, CC Glass/Grid/Image Wipe, CC Jaws, CC Line Sweep, CC Radial ScaleWipe, CC Scale Wipe, CC Twister, CC WarpoMatic, Radial Shadow, CC Bender, CC Blobbylize, CC Cylinder, CC Sphere, CC Spotlight, CC Environment, 3D Glasses) and text (Numbers, Timecode: CPU glyph coverage, GPU composite)
2026-10-03 17:48:02 -04:00
|
|
|
mod fx_text;
|
2026-10-03 17:57:03 -04:00
|
|
|
mod fx_time;
|
2026-10-03 08:13:58 -04:00
|
|
|
mod fx_tone;
|
M13.22: GPU transitions and perspective (Block Dissolve, CC Glass/Grid/Image Wipe, CC Jaws, CC Line Sweep, CC Radial ScaleWipe, CC Scale Wipe, CC Twister, CC WarpoMatic, Radial Shadow, CC Bender, CC Blobbylize, CC Cylinder, CC Sphere, CC Spotlight, CC Environment, 3D Glasses) and text (Numbers, Timecode: CPU glyph coverage, GPU composite)
2026-10-03 17:48:02 -04:00
|
|
|
mod fx_transition;
|
2026-10-03 17:53:23 -04:00
|
|
|
mod fx_vr;
|
2026-10-03 10:31:31 -04:00
|
|
|
mod fx_warp;
|
2026-10-02 10:59:08 -04:00
|
|
|
mod ops;
|
2026-10-03 02:44:36 -04:00
|
|
|
mod particles;
|
2026-10-06 16:40:12 -05:00
|
|
|
mod readback;
|
2026-10-02 10:59:08 -04:00
|
|
|
mod walk;
|
|
|
|
|
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
2026-10-03 10:31:31 -04:00
|
|
|
pub use context::{GpuContext, GpuImage, TransferStats};
|
2026-10-02 10:59:08 -04:00
|
|
|
use effectcraft_effects::Buf;
|
|
|
|
|
use effectcraft_project::ItemId;
|
|
|
|
|
use effectcraft_raster::Image;
|
|
|
|
|
use effectcraft_render::{Accelerator, FxStep, Renderer};
|
|
|
|
|
use effectcraft_time::Tick;
|
|
|
|
|
pub use wgpu;
|
|
|
|
|
|
|
|
|
|
use crate::context::Enc;
|
|
|
|
|
|
|
|
|
|
/// The GPU compositor (cheap to clone; one device shared by all clones).
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
pub struct Gpu {
|
|
|
|
|
ctx: Arc<GpuContext>,
|
2026-10-03 10:31:31 -04:00
|
|
|
/// Backend::Auto's per-comp CPU / GPU timings.
|
|
|
|
|
auto: Arc<effectcraft_render::AutoPick>,
|
2026-10-02 10:59:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// A viewer frame left on the GPU: premultiplied RGBA8 (`wgpu::TextureFormat::Rgba8Unorm`),
|
|
|
|
|
/// ready for `egui_wgpu::Renderer::register_native_texture`.
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
|
pub struct DisplayFrame {
|
|
|
|
|
pub texture: wgpu::Texture,
|
|
|
|
|
pub width: u32,
|
|
|
|
|
pub height: u32,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Gpu {
|
|
|
|
|
/// On a device of its own (CLI, tests, benchmarks); `None` without a usable adapter.
|
|
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
|
|
|
pub fn headless() -> Option<Gpu> {
|
2026-10-08 18:09:01 +07:00
|
|
|
Gpu::try_headless().map_err(|e| log::info!("gpu: {e}")).ok()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// [`Gpu::headless`], with why there is none.
|
|
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
|
|
|
pub fn try_headless() -> Result<Gpu, String> {
|
|
|
|
|
pollster::block_on(GpuContext::request()).map(Gpu::from_context)
|
2026-10-02 10:59:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// On an existing device (the desktop app shares egui-wgpu's).
|
|
|
|
|
pub fn new(adapter: &wgpu::Adapter, device: wgpu::Device, queue: wgpu::Queue) -> Result<Gpu, String> {
|
|
|
|
|
GpuContext::new(adapter, device, queue).map(Gpu::from_context)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn from_context(ctx: GpuContext) -> Gpu {
|
2026-10-03 10:31:31 -04:00
|
|
|
Gpu { ctx: Arc::new(ctx), auto: Default::default() }
|
2026-10-02 10:59:08 -04:00
|
|
|
}
|
|
|
|
|
|
2026-10-03 18:35:03 -04:00
|
|
|
/// A device of its own without blocking, with deferred readbacks (a browser worker, see
|
|
|
|
|
/// [`deferred`]); natively the same device works too (tests). `Err` says why there is none.
|
|
|
|
|
pub async fn request_deferred() -> Result<Gpu, String> {
|
|
|
|
|
let mut ctx = GpuContext::request().await?;
|
|
|
|
|
ctx.set_deferred(true);
|
|
|
|
|
Ok(Gpu::from_context(ctx))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// [`Gpu::request_deferred`] blocking (tests of the browser worker's path, natively).
|
|
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
|
|
|
pub fn headless_deferred() -> Option<Gpu> {
|
|
|
|
|
pollster::block_on(Gpu::request_deferred()).map_err(|e| log::info!("gpu: {e}")).ok()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The deferred readback state, when readbacks are deferred.
|
|
|
|
|
pub fn deferred(&self) -> Option<&Arc<deferred::Deferred>> {
|
|
|
|
|
self.ctx.deferred()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Resolves once no deferred readback is in flight (immediately without deferred readbacks).
|
|
|
|
|
pub async fn settled(&self) {
|
|
|
|
|
if let Some(d) = self.ctx.deferred() {
|
|
|
|
|
d.settled().await;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Deliver finished readbacks without blocking (native; the browser delivers them itself).
|
|
|
|
|
pub fn poll(&self) {
|
|
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
2026-10-06 16:40:12 -05:00
|
|
|
let _ = self.ctx.poll_readbacks(wgpu::PollType::Poll);
|
2026-10-03 18:35:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// `{passes, readbacks, inFlight}` of deferred rendering (diagnostics).
|
|
|
|
|
pub fn deferred_stats(&self) -> Option<(u64, u64, usize)> {
|
|
|
|
|
let d = self.ctx.deferred()?;
|
|
|
|
|
Some((d.passes.load(std::sync::atomic::Ordering::Relaxed), d.readbacks.load(std::sync::atomic::Ordering::Relaxed), d.in_flight()))
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-02 10:59:08 -04:00
|
|
|
pub fn context(&self) -> &GpuContext {
|
|
|
|
|
&self.ctx
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn device(&self) -> &wgpu::Device {
|
|
|
|
|
&self.ctx.device
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Render a top-level comp frame and leave it on the GPU as a display texture (no
|
|
|
|
|
/// readback unless a CPU fallback step needs one). `None` = render on the CPU.
|
|
|
|
|
pub fn render_display(&self, r: &Renderer, comp: ItemId, t: Tick) -> Option<DisplayFrame> {
|
2026-10-06 16:40:12 -05:00
|
|
|
self.ctx.check_health().map_err(|e| log::error!("gpu display: {e}")).ok()?;
|
2026-10-02 10:59:08 -04:00
|
|
|
let mut e = Enc::new(&self.ctx);
|
|
|
|
|
let img = walk::render(&mut e, r, comp, t)?;
|
|
|
|
|
let texture = e.display(&img);
|
|
|
|
|
e.submit();
|
2026-10-06 16:40:12 -05:00
|
|
|
// Reject failures observed during rendering/submission before publishing the frame.
|
|
|
|
|
// A later device fault still requires the presentation host's lifecycle handling.
|
|
|
|
|
self.ctx.check_health().map_err(|e| log::error!("gpu display: {e}")).ok()?;
|
2026-10-02 10:59:08 -04:00
|
|
|
Some(DisplayFrame { texture, width: img.width, height: img.height })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Read a display frame back as premultiplied RGBA8 (Info panel sampling, eyedroppers).
|
|
|
|
|
pub fn read_display(&self, f: &DisplayFrame) -> Option<Vec<u8>> {
|
|
|
|
|
Enc::new(&self.ctx).read_texture(&f.texture, f.width, f.height, 4)
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-02 23:42:00 -04:00
|
|
|
/// [`Gpu::read_display`] without blocking (the browser's main thread): `done` gets the bytes
|
|
|
|
|
/// once the GPU has them.
|
|
|
|
|
pub fn read_display_async(&self, f: &DisplayFrame, done: impl FnOnce(Option<Vec<u8>>) + wgpu::WasmNotSend + 'static) {
|
2026-10-06 16:40:12 -05:00
|
|
|
if let Err(e) = self.ctx.check_health() {
|
|
|
|
|
log::error!("gpu display readback: {e}");
|
|
|
|
|
crate::readback::reject(done, e);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-10-02 23:42:00 -04:00
|
|
|
Enc::new(&self.ctx).read_texture_async(&f.texture, f.width, f.height, 4, done);
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-02 10:59:08 -04:00
|
|
|
/// Render a frame on the GPU and read it back (`None` = not handled).
|
|
|
|
|
pub fn render(&self, r: &Renderer, comp: ItemId, t: Tick) -> Option<Image> {
|
2026-10-06 16:40:12 -05:00
|
|
|
self.ctx.check_health().ok()?;
|
2026-10-02 10:59:08 -04:00
|
|
|
if !self.ctx.can_readback() {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
2026-10-03 18:35:03 -04:00
|
|
|
if let Some(d) = self.ctx.deferred.clone() {
|
|
|
|
|
return self.render_deferred(&d, r, comp, t);
|
|
|
|
|
}
|
2026-10-02 10:59:08 -04:00
|
|
|
let mut e = Enc::new(&self.ctx);
|
|
|
|
|
let img = walk::render(&mut e, r, comp, t)?;
|
|
|
|
|
e.download(&img)
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-03 18:35:03 -04:00
|
|
|
/// [`Gpu::render`] with deferred readbacks: the frame's readback is keyed by comp, time and
|
|
|
|
|
/// render options; until it arrives (or while layer steps still miss) the pass gets a
|
|
|
|
|
/// placeholder.
|
|
|
|
|
fn render_deferred(&self, d: &Arc<deferred::Deferred>, r: &Renderer, comp: ItemId, t: Tick) -> Option<Image> {
|
|
|
|
|
let mut k = deferred::Key::new(2);
|
|
|
|
|
k.u64(comp.0);
|
|
|
|
|
k.u64(t.0 as u64);
|
|
|
|
|
k.debug(&r.opts);
|
|
|
|
|
let key = k.finish();
|
|
|
|
|
let image = |rb: deferred::Readback| -> Option<Image> {
|
|
|
|
|
let mut img = Image::new(rb.width, rb.height);
|
|
|
|
|
let dst: &mut [u8] = bytemuck::cast_slice_mut(&mut img.data);
|
|
|
|
|
(dst.len() == rb.bytes.len()).then(|| dst.copy_from_slice(&rb.bytes))?;
|
|
|
|
|
Some(img)
|
|
|
|
|
};
|
|
|
|
|
match d.lookup(key) {
|
|
|
|
|
deferred::Lookup::Ready(rb) => return rb.and_then(image),
|
|
|
|
|
deferred::Lookup::InFlight => {
|
|
|
|
|
d.miss();
|
|
|
|
|
return Some(Image::new(1, 1));
|
|
|
|
|
}
|
|
|
|
|
deferred::Lookup::Absent => {}
|
|
|
|
|
}
|
|
|
|
|
let misses = d.misses();
|
|
|
|
|
let mut e = Enc::new(&self.ctx);
|
|
|
|
|
let img = walk::render(&mut e, r, comp, t)?;
|
|
|
|
|
if d.misses() != misses {
|
|
|
|
|
// Layer steps are still in flight: this pass's canvas is not the frame.
|
|
|
|
|
return Some(Image::new(1, 1));
|
|
|
|
|
}
|
|
|
|
|
match e.read_keyed(&img, key, [0.0; 2], 1.0) {
|
|
|
|
|
Some(rb) => rb.and_then(image),
|
|
|
|
|
None => Some(Image::new(1, 1)),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-06 16:40:12 -05:00
|
|
|
/// Run work in a native thread-local out-of-memory scope. A failed result is discarded
|
|
|
|
|
/// and cached allocations are released; callers can retry with a fresh CPU renderer.
|
|
|
|
|
/// Browser callers use the host/owned-device failure bridge and bounded readbacks instead
|
|
|
|
|
/// of blocking their event loop on an error-scope future.
|
2026-10-07 02:06:15 +07:00
|
|
|
pub fn within_memory<T>(&self, f: impl FnOnce() -> T) -> Result<T, String> {
|
2026-10-06 16:40:12 -05:00
|
|
|
self.ctx.check_health()?;
|
2026-10-07 02:06:15 +07:00
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
|
|
|
{
|
|
|
|
|
let scope = self.ctx.device.push_error_scope(wgpu::ErrorFilter::OutOfMemory);
|
|
|
|
|
let out = f();
|
|
|
|
|
match pollster::block_on(scope.pop()) {
|
|
|
|
|
Some(e) => {
|
|
|
|
|
self.ctx.clear_uploads();
|
|
|
|
|
Err(e.to_string())
|
|
|
|
|
}
|
2026-10-06 16:40:12 -05:00
|
|
|
None => self.ctx.check_health().map(|()| out),
|
2026-10-07 02:06:15 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
2026-10-06 16:40:12 -05:00
|
|
|
{
|
|
|
|
|
let out = f();
|
|
|
|
|
self.ctx.check_health().map(|()| out)
|
|
|
|
|
}
|
2026-10-07 02:06:15 +07:00
|
|
|
}
|
|
|
|
|
|
2026-10-06 16:40:12 -05:00
|
|
|
/// Wait for submitted GPU work with the readback deadline (benchmarks).
|
2026-10-02 10:59:08 -04:00
|
|
|
pub fn wait(&self) {
|
2026-10-06 16:40:12 -05:00
|
|
|
let _ = self.ctx.poll_readbacks(wgpu::PollType::Wait { submission_index: None, timeout: Some(crate::readback::TIMEOUT) });
|
2026-10-02 10:59:08 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Accelerator for Gpu {
|
|
|
|
|
fn name(&self) -> String {
|
|
|
|
|
self.ctx.name.clone()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn comp_frame(&self, r: &Renderer, comp: ItemId, t: Tick) -> Option<Image> {
|
|
|
|
|
self.render(r, comp, t)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn supports_effect(&self, id: &str) -> bool {
|
2026-10-06 16:40:12 -05:00
|
|
|
self.ctx.check_health().is_ok() && self.ctx.can_readback() && effects::supports(id)
|
2026-10-02 10:59:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn effects(&self, chain: &[FxStep], buf: &Buf, levels: Option<f32>) -> Option<Buf> {
|
2026-10-06 16:40:12 -05:00
|
|
|
self.ctx.check_health().ok()?;
|
2026-10-02 10:59:08 -04:00
|
|
|
effects::run_chain(&mut Enc::new(&self.ctx), chain, buf, levels)
|
|
|
|
|
}
|
2026-10-02 21:27:59 -04:00
|
|
|
|
|
|
|
|
fn raster_3d(&self, scene: &effectcraft_render::three_d::adv::Scene) -> Option<effectcraft_render::three_d::adv::Target> {
|
2026-10-06 16:40:12 -05:00
|
|
|
self.ctx.check_health().ok()?;
|
2026-10-02 21:27:59 -04:00
|
|
|
adv3d::render(&self.ctx, scene)
|
|
|
|
|
}
|
2026-10-03 02:44:36 -04:00
|
|
|
|
2026-10-03 09:38:11 -04:00
|
|
|
fn render_3d(&self, run: &effectcraft_render::three_d::adv::Prepared) -> Option<effectcraft_render::three_d::adv::Rendered> {
|
2026-10-06 16:40:12 -05:00
|
|
|
self.ctx.check_health().ok()?;
|
2026-10-03 09:38:11 -04:00
|
|
|
adv3d::render_prepared(&self.ctx, run)
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-03 02:44:36 -04:00
|
|
|
fn particles(&self) -> Option<&dyn effectcraft_effects::psim::ParticleSim> {
|
2026-10-06 16:40:12 -05:00
|
|
|
self.ctx.check_health().ok()?;
|
2026-10-04 02:57:17 -04:00
|
|
|
self.ctx.can_readback().then_some(self as &dyn effectcraft_effects::psim::ParticleSim)
|
2026-10-03 02:44:36 -04:00
|
|
|
}
|
2026-10-03 10:31:31 -04:00
|
|
|
|
|
|
|
|
fn auto_pick(&self) -> Option<&effectcraft_render::AutoPick> {
|
|
|
|
|
Some(&self.auto)
|
|
|
|
|
}
|
2026-10-03 18:35:03 -04:00
|
|
|
|
|
|
|
|
fn frame_begin(&self) {
|
|
|
|
|
if let Some(d) = self.ctx.deferred() {
|
|
|
|
|
d.frame_begin();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn pass_begin(&self) {
|
|
|
|
|
if let Some(d) = self.ctx.deferred() {
|
|
|
|
|
d.pass_begin();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn pass_missed(&self) -> bool {
|
|
|
|
|
self.ctx.deferred().is_some_and(|d| d.missed())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn miss_gate(&self) -> Option<Arc<std::sync::atomic::AtomicBool>> {
|
|
|
|
|
self.ctx.deferred().map(|d| d.gate())
|
|
|
|
|
}
|
2026-10-04 02:57:17 -04:00
|
|
|
|
|
|
|
|
fn settle(&self) -> Option<std::pin::Pin<Box<dyn std::future::Future<Output = ()> + '_>>> {
|
|
|
|
|
let d = self.ctx.deferred()?.clone();
|
|
|
|
|
// Natively the device delivers the readbacks when polled: wait for them here.
|
|
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
|
|
|
if d.in_flight() > 0 {
|
2026-10-06 16:40:12 -05:00
|
|
|
let _ = self.ctx.poll_readbacks(wgpu::PollType::Wait { submission_index: None, timeout: Some(crate::readback::TIMEOUT) });
|
2026-10-04 02:57:17 -04:00
|
|
|
}
|
|
|
|
|
Some(Box::pin(async move { d.settled().await }))
|
|
|
|
|
}
|
2026-10-03 02:44:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl effectcraft_effects::psim::ParticleSim for Gpu {
|
|
|
|
|
fn simulate(&self, req: &effectcraft_effects::psim::SimRequest) -> Option<Vec<effectcraft_effects::psim::SimParticle>> {
|
2026-10-06 16:40:12 -05:00
|
|
|
self.ctx.check_health().ok()?;
|
2026-10-03 02:44:36 -04:00
|
|
|
particles::simulate(&self.ctx, req)
|
|
|
|
|
}
|
2026-10-02 10:59:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests;
|
2026-10-02 21:27:59 -04:00
|
|
|
#[cfg(test)]
|
2026-10-03 02:15:01 -04:00
|
|
|
mod tests_3d;
|
|
|
|
|
#[cfg(test)]
|
2026-10-03 02:23:01 -04:00
|
|
|
mod tests_adjust;
|
|
|
|
|
#[cfg(test)]
|
2026-10-02 21:27:59 -04:00
|
|
|
mod tests_adv3d;
|
2026-10-03 02:44:36 -04:00
|
|
|
#[cfg(test)]
|
2026-10-03 18:35:03 -04:00
|
|
|
mod tests_deferred;
|
|
|
|
|
#[cfg(test)]
|
2026-10-04 02:57:17 -04:00
|
|
|
mod tests_deferred_jobs;
|
|
|
|
|
#[cfg(test)]
|
2026-10-03 02:46:52 -04:00
|
|
|
mod tests_fx_color;
|
2026-10-03 02:54:53 -04:00
|
|
|
#[cfg(test)]
|
2026-10-03 17:33:41 -04:00
|
|
|
mod tests_fx_depth;
|
|
|
|
|
#[cfg(test)]
|
M12.7: GPU distort/stylize effects (Turbulent Displace, Displacement Map, Wave Warp, Ripple, Twirl, Bulge, CC Lens, Mesh Warp, Mosaic, Find Edges, Emboss)
2026-10-03 02:42:43 -04:00
|
|
|
mod tests_fx_distort;
|
2026-10-03 02:47:03 -04:00
|
|
|
#[cfg(test)]
|
2026-10-03 10:53:00 -04:00
|
|
|
mod tests_fx_extra;
|
|
|
|
|
#[cfg(test)]
|
M13.28: GPU generators (fx_gen2): Lightning, Advanced Lightning, Beam, Lens Flare, Radio Waves, Vegas, Stroke, Scribble, Write-on, Paint Bucket, Eyedropper Fill, CC Glue Gun, CC Threads, Audio Spectrum/Waveform, Basic Text, Path Text
2026-10-04 02:56:00 -04:00
|
|
|
mod tests_fx_gen2;
|
|
|
|
|
#[cfg(test)]
|
M12.7: GPU blur/transition/generate effects (radial, camera lens, CC radial fast, wipes, venetian, cell pattern, checkerboard, grid, 4-color, noise, add grain)
2026-10-03 02:46:09 -04:00
|
|
|
mod tests_fx_generate;
|
2026-10-03 02:54:53 -04:00
|
|
|
#[cfg(test)]
|
2026-10-03 07:51:33 -04:00
|
|
|
mod tests_fx_key;
|
|
|
|
|
#[cfg(test)]
|
2026-10-03 17:31:26 -04:00
|
|
|
mod tests_fx_light;
|
|
|
|
|
#[cfg(test)]
|
2026-10-03 17:43:24 -04:00
|
|
|
mod tests_fx_lut;
|
|
|
|
|
#[cfg(test)]
|
2026-10-03 07:51:33 -04:00
|
|
|
mod tests_fx_noise;
|
|
|
|
|
#[cfg(test)]
|
2026-10-04 01:35:56 -04:00
|
|
|
mod tests_fx_particles;
|
|
|
|
|
#[cfg(test)]
|
M13.28: GPU pixel ports (fx_pixel2): CC Cross/Radial/Vector Blur, Reduce Interlace Flicker, CC Composite, Color Link, Cineon, HDR Compander/Highlight Compression, Grow Bounds, CC Overbrights, CC Block Load, CC Burn Film, CC Glass/Plastic, CC HexTile, CC Mr. Smoothie, Inner/Outer Key, CC Simple Wire Removal, Basic 3D
2026-10-04 01:33:54 -04:00
|
|
|
mod tests_fx_pixel2;
|
|
|
|
|
#[cfg(test)]
|
2026-10-03 18:35:22 -04:00
|
|
|
mod tests_fx_sim;
|
|
|
|
|
#[cfg(test)]
|
2026-10-03 07:51:33 -04:00
|
|
|
mod tests_fx_stylize;
|
|
|
|
|
#[cfg(test)]
|
M13.22: GPU transitions and perspective (Block Dissolve, CC Glass/Grid/Image Wipe, CC Jaws, CC Line Sweep, CC Radial ScaleWipe, CC Scale Wipe, CC Twister, CC WarpoMatic, Radial Shadow, CC Bender, CC Blobbylize, CC Cylinder, CC Sphere, CC Spotlight, CC Environment, 3D Glasses) and text (Numbers, Timecode: CPU glyph coverage, GPU composite)
2026-10-03 17:48:02 -04:00
|
|
|
mod tests_fx_text;
|
|
|
|
|
#[cfg(test)]
|
2026-10-03 17:57:03 -04:00
|
|
|
mod tests_fx_time;
|
|
|
|
|
#[cfg(test)]
|
2026-10-03 08:13:58 -04:00
|
|
|
mod tests_fx_tone;
|
|
|
|
|
#[cfg(test)]
|
M13.22: GPU transitions and perspective (Block Dissolve, CC Glass/Grid/Image Wipe, CC Jaws, CC Line Sweep, CC Radial ScaleWipe, CC Scale Wipe, CC Twister, CC WarpoMatic, Radial Shadow, CC Bender, CC Blobbylize, CC Cylinder, CC Sphere, CC Spotlight, CC Environment, 3D Glasses) and text (Numbers, Timecode: CPU glyph coverage, GPU composite)
2026-10-03 17:48:02 -04:00
|
|
|
mod tests_fx_transition;
|
|
|
|
|
#[cfg(test)]
|
2026-10-03 17:53:23 -04:00
|
|
|
mod tests_fx_vr;
|
|
|
|
|
#[cfg(test)]
|
2026-10-03 10:31:31 -04:00
|
|
|
mod tests_fx_warp;
|
2026-10-06 16:40:12 -05:00
|
|
|
#[cfg(all(test, not(target_arch = "wasm32")))]
|
|
|
|
|
mod tests_init;
|
2026-10-03 10:31:31 -04:00
|
|
|
#[cfg(test)]
|
2026-10-03 02:54:53 -04:00
|
|
|
mod tests_particles;
|