M13.30: web depth and polish
- GPU in browser job workers: each job worker opens its own WebGPU device (deferred readbacks); the Render Queue export and the analyses' frame loops are futures (render::passes, offload::run_request_async) whose frames render in passes, awaiting the device between them. GPU particles and Advanced 3D read back under keys too. workers.jobs reports passes and readbacks; the smoke test measures them. - Layer buffers in the browser's OPFS disk cache: frame workers back their layer caches with a PrefetchStore; the page plans what to fetch before a request from recent misses (LayerPrefetch over the shared DiskIndex). - Templates embed footage (default on, size-capped with a warning) and creating from a template extracts it next to the new project / into browser storage. - ICC LUT profiles (lut8/lut16/lutAtoB/lutBtoA, from the public ICC spec) in Simulate Output > My Custom RGB, baked into a 3D LUT for the viewer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
d39c0e818c
commit
f3715aac32
@@ -9,10 +9,14 @@
|
||||
//! segmentations a propagation job sends back are relayed to them.
|
||||
//!
|
||||
//! **Worker side** — `web/worker.js` instantiates the same wasm module (the page's compiled
|
||||
//! `WebAssembly.Module`, so nothing is compiled twice) and calls [`worker_init`], then
|
||||
//! `WebAssembly.Module`, so nothing is compiled twice) and calls [`worker_init`] and
|
||||
//! [`worker_job_init`] (the worker's own WebGPU device, where workers have WebGPU), then
|
||||
//! [`worker_file`] per footage file and [`worker_job`] per job: a plain engine session (footage
|
||||
//! from memory, expressions, the exporter) runs it blocking and posts replies as it goes. Each
|
||||
//! worker has its own memory: no shared-memory threads, so this works on stable Rust.
|
||||
//! from memory, expressions, the exporter) runs it and posts replies as it goes. With a device,
|
||||
//! the job's frames (Render Queue frames, analysis input frames, particles, Advanced 3D) render
|
||||
//! on it in passes, the job awaiting the GPU's readbacks between them
|
||||
//! ([`effectcraft_engine::offload::run_request_async`]). Each worker has its own memory: no
|
||||
//! shared-memory threads, so this works on stable Rust.
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
@@ -32,6 +36,8 @@ extern "C" {
|
||||
fn worker_cancel(id: f64);
|
||||
#[wasm_bindgen(js_name = workerStats)]
|
||||
pub fn stats() -> JsValue;
|
||||
#[wasm_bindgen(js_name = setJobWorkerGpu)]
|
||||
pub fn set_job_worker_gpu(on: bool);
|
||||
}
|
||||
|
||||
type OnMessage = Closure<dyn FnMut(String, JsValue, JsValue, JsValue)>;
|
||||
@@ -42,6 +48,8 @@ thread_local! {
|
||||
/// The worker's session and its media pool.
|
||||
static SESSION: RefCell<Option<Session>> = const { RefCell::new(None) };
|
||||
static POOL: RefCell<Option<Arc<effectcraft_media::MediaPool>>> = const { RefCell::new(None) };
|
||||
/// The job worker's GPU device (deferred readbacks), when it has one.
|
||||
static GPU: RefCell<Option<effectcraft_gpu::Gpu>> = const { RefCell::new(None) };
|
||||
}
|
||||
|
||||
/// The page's offload: one worker per running job (idle workers are reused).
|
||||
@@ -169,9 +177,42 @@ pub fn worker_file(path: String, bytes: js_sys::Uint8Array) {
|
||||
});
|
||||
}
|
||||
|
||||
/// Run one job (a JSON [`WorkerRequest`]) and post its replies.
|
||||
/// A job worker's GPU (called once by `web/worker.js` after `workerInit`): with `gpu` and
|
||||
/// WebGPU in workers, its own device with deferred readbacks becomes the session's
|
||||
/// accelerator. Posts `{type: "gpu", gpu?, error?}`.
|
||||
#[wasm_bindgen(js_name = workerJobInit)]
|
||||
pub async fn worker_job_init(gpu: bool) {
|
||||
let r = if !gpu {
|
||||
Err("GPU job workers are off (?nogpuworkers)".to_string())
|
||||
} else if !crate::frames::has_web_gpu() {
|
||||
Err("no WebGPU in workers".to_string())
|
||||
} else {
|
||||
effectcraft_gpu::Gpu::request_deferred().await
|
||||
};
|
||||
let msg = match r {
|
||||
Ok(g) => {
|
||||
let name = effectcraft_engine::render::Accelerator::name(&g);
|
||||
SESSION.with(|c| {
|
||||
if let Some(s) = c.borrow_mut().as_mut() {
|
||||
s.accel = Some(Arc::new(g.clone()));
|
||||
}
|
||||
});
|
||||
GPU.with(|c| *c.borrow_mut() = Some(g));
|
||||
log::info!("job worker: GPU {name}");
|
||||
obj(&[("type", "gpu".into()), ("gpu", name.into())])
|
||||
}
|
||||
Err(e) => {
|
||||
log::info!("job worker: CPU only ({e})");
|
||||
obj(&[("type", "gpu".into()), ("error", e.into())])
|
||||
}
|
||||
};
|
||||
post(&msg, None);
|
||||
}
|
||||
|
||||
/// Run one job (a JSON [`WorkerRequest`]) and post its replies, then `{type: "stats", gpu,
|
||||
/// passes, readbacks, ms}` (the device's render passes and readbacks during the job).
|
||||
#[wasm_bindgen(js_name = workerJob)]
|
||||
pub fn worker_job(json: String) {
|
||||
pub async fn worker_job(json: String) {
|
||||
let send: effectcraft_engine::offload::Post = Rc::new(|r: WorkerReply| {
|
||||
let done = matches!(r, WorkerReply::Done);
|
||||
let t = serde_json::to_string(&r).unwrap_or_default();
|
||||
@@ -185,13 +226,37 @@ pub fn worker_job(json: String) {
|
||||
return;
|
||||
}
|
||||
};
|
||||
SESSION.with(|c| {
|
||||
let mut c = c.borrow_mut();
|
||||
let Some(s) = c.as_mut() else {
|
||||
send(WorkerReply::Failed { error: "worker not initialised".into() });
|
||||
send(WorkerReply::Done);
|
||||
return;
|
||||
};
|
||||
effectcraft_engine::offload::run_request(s, req, &send);
|
||||
// The session leaves its slot while the job runs (the job awaits the GPU in between;
|
||||
// messages are handled one at a time, so nothing else needs it meanwhile).
|
||||
let Some(mut s) = SESSION.with(|c| c.borrow_mut().take()) else {
|
||||
send(WorkerReply::Failed { error: "worker not initialised".into() });
|
||||
send(WorkerReply::Done);
|
||||
return;
|
||||
};
|
||||
let gpu = GPU.with(|c| c.borrow().clone());
|
||||
let before = gpu.as_ref().and_then(|g| g.deferred_stats()).unwrap_or_default();
|
||||
let t0 = web_time::Instant::now();
|
||||
let kind = format!("{:?}", req.job.kind());
|
||||
// `Done` is posted last by the job; the stats go out just before it.
|
||||
let stats_sent = Rc::new(std::cell::Cell::new(false));
|
||||
let (g2, s2) = (gpu.clone(), stats_sent.clone());
|
||||
let send2: effectcraft_engine::offload::Post = Rc::new(move |r: WorkerReply| {
|
||||
if matches!(r, WorkerReply::Done) && !s2.replace(true) {
|
||||
let after = g2.as_ref().and_then(|g| g.deferred_stats()).unwrap_or_default();
|
||||
post(
|
||||
&obj(&[
|
||||
("type", "stats".into()),
|
||||
("kind", kind.as_str().into()),
|
||||
("gpu", JsValue::from_bool(g2.is_some())),
|
||||
("passes", ((after.0 - before.0) as f64).into()),
|
||||
("readbacks", ((after.1 - before.1) as f64).into()),
|
||||
("ms", (t0.elapsed().as_secs_f64() * 1000.0).into()),
|
||||
]),
|
||||
None,
|
||||
);
|
||||
}
|
||||
send(r);
|
||||
});
|
||||
effectcraft_engine::offload::run_request_async(&mut s, req, &send2).await;
|
||||
SESSION.with(|c| *c.borrow_mut() = Some(s));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user