| author | |
| committer | |
| log | a410bb327c81f2970d3c7e9fa129158d7984c289 |
| tree | d751f6397c7305a250f42bc353ab89841fdb6463 |
| parent | ab2fbef74138aa8501feefc592be9ef0bd07feee |
| signature | Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU |
5 files changed, 244 insertions(+), 78 deletions(-)
crates/engine/src/bin/render_check.rs+62-21| ... | ... | @@ -244,6 +244,7 @@ fn run_batch_render( |
| 244 | 244 | |
| 245 | 245 | let mut loop_err: Option<String> = None; |
| 246 | 246 | const PREFETCH_LOOKAHEAD: usize = 12; |
| 247 | engine.prewarm_core_pipelines(); | |
| 247 | 248 | engine.media.preload_frame_loaders_with_proxy( |
| 248 | 249 | &comp, |
| 249 | 250 | target, |
| ... | ... | @@ -263,6 +264,7 @@ fn run_batch_render( |
| 263 | 264 | engine.use_proxy_clips, |
| 264 | 265 | ); |
| 265 | 266 | } |
| 267 | let mut pending: Option<(engine::PendingReadback, i64, usize, [u32; 2], engine::EvalStats)> = None; | |
| 266 | 268 | for (idx, f) in (start..=end).enumerate() { |
| 267 | 269 | if failed.load(Ordering::Acquire) { |
| 268 | 270 | break; |
| ... | ... | @@ -280,34 +282,73 @@ fn run_batch_render( |
| 280 | 282 | ); |
| 281 | 283 | } |
| 282 | 284 | let (tex, stats) = engine.evaluate(&comp, target, f as f64); |
| 283 | let pixels = match engine.readback_rgba(&tex) { | |
| 284 | Ok(px) => px, | |
| 285 | let next_rb = match engine.begin_readback_rgba(&tex) { | |
| 286 | Ok(rb) => rb, | |
| 285 | 287 | Err(e) => { |
| 286 | 288 | loop_err = Some(format!("GPU readback failed at frame {f}: {e}")); |
| 287 | 289 | break; |
| 288 | 290 | } |
| 289 | 291 | }; |
| 290 | let out_file = out_dir.join(format!("{f:04}.png")); | |
| 291 | if tx | |
| 292 | .send(RenderEncodeJob { | |
| 293 | path: out_file, | |
| 294 | size: tex.size, | |
| 295 | pixels, | |
| 296 | }) | |
| 297 | .is_err() | |
| 292 | if let Some((prev_rb, prev_f, prev_idx, prev_size, prev_stats)) = | |
| 293 | pending.replace((next_rb, f, idx, tex.size, stats)) | |
| 298 | 294 | { |
| 299 | break; | |
| 295 | let pixels = match prev_rb.finish(&engine) { | |
| 296 | Ok(px) => px, | |
| 297 | Err(e) => { | |
| 298 | loop_err = Some(format!("GPU readback failed at frame {prev_f}: {e}")); | |
| 299 | break; | |
| 300 | } | |
| 301 | }; | |
| 302 | let out_file = out_dir.join(format!("{prev_f:04}.png")); | |
| 303 | if tx | |
| 304 | .send(RenderEncodeJob { | |
| 305 | path: out_file, | |
| 306 | size: prev_size, | |
| 307 | pixels, | |
| 308 | }) | |
| 309 | .is_err() | |
| 310 | { | |
| 311 | break; | |
| 312 | } | |
| 313 | if prev_idx == 0 || (prev_idx + 1) % 10 == 0 || prev_idx + 1 == total { | |
| 314 | let elapsed = t_all.elapsed().as_secs_f64().max(1e-6); | |
| 315 | let fps = (prev_idx + 1) as f64 / elapsed; | |
| 316 | eprintln!( | |
| 317 | " [{:>4}/{total}] f{prev_f:04} | eval={:.1}ms | avg={fps:.1} fps | vram={:.0}MB | unsupported={:?}", | |
| 318 | prev_idx + 1, | |
| 319 | prev_stats.eval_ms, | |
| 320 | prev_stats.cached_vram_mb, | |
| 321 | prev_stats.unsupported_nodes, | |
| 322 | ); | |
| 323 | } | |
| 300 | 324 | } |
| 301 | if idx == 0 || (idx + 1) % 10 == 0 || idx + 1 == total { | |
| 302 | let elapsed = t_all.elapsed().as_secs_f64().max(1e-6); | |
| 303 | let fps = (idx + 1) as f64 / elapsed; | |
| 304 | eprintln!( | |
| 305 | " [{:>4}/{total}] f{f:04} | eval={:.1}ms | avg={fps:.1} fps | vram={:.0}MB | unsupported={:?}", | |
| 306 | idx + 1, | |
| 307 | stats.eval_ms, | |
| 308 | stats.cached_vram_mb, | |
| 309 | stats.unsupported_nodes, | |
| 310 | ); | |
| 325 | } | |
| 326 | if loop_err.is_none() && !failed.load(Ordering::Acquire) { | |
| 327 | if let Some((prev_rb, prev_f, prev_idx, prev_size, prev_stats)) = pending.take() { | |
| 328 | match prev_rb.finish(&engine) { | |
| 329 | Ok(pixels) => { | |
| 330 | let out_file = out_dir.join(format!("{prev_f:04}.png")); | |
| 331 | let _ = tx.send(RenderEncodeJob { | |
| 332 | path: out_file, | |
| 333 | size: prev_size, | |
| 334 | pixels, | |
| 335 | }); | |
| 336 | if prev_idx == 0 || (prev_idx + 1) % 10 == 0 || prev_idx + 1 == total { | |
| 337 | let elapsed = t_all.elapsed().as_secs_f64().max(1e-6); | |
| 338 | let fps = (prev_idx + 1) as f64 / elapsed; | |
| 339 | eprintln!( | |
| 340 | " [{:>4}/{total}] f{prev_f:04} | eval={:.1}ms | avg={fps:.1} fps | vram={:.0}MB | unsupported={:?}", | |
| 341 | prev_idx + 1, | |
| 342 | prev_stats.eval_ms, | |
| 343 | prev_stats.cached_vram_mb, | |
| 344 | prev_stats.unsupported_nodes, | |
| 345 | ); | |
| 346 | } | |
| 347 | } | |
| 348 | Err(e) => { | |
| 349 | loop_err = Some(format!("GPU readback failed at frame {prev_f}: {e}")); | |
| 350 | } | |
| 351 | } | |
| 311 | 352 | } |
| 312 | 353 | } |
| 313 | 354 |
crates/engine/src/eval/mod.rs+22-1| ... | ... | @@ -30,7 +30,7 @@ mod dispatch; |
| 30 | 30 | mod output_cache; |
| 31 | 31 | |
| 32 | 32 | use dispatch::UniformParams; |
| 33 | pub use dispatch::{create_texture, create_texture_dod, create_texture_dod_fmt}; | |
| 33 | pub use dispatch::{PendingReadback, create_texture, create_texture_dod, create_texture_dod_fmt}; | |
| 34 | 34 | use output_cache::OutputCache; |
| 35 | 35 | use registry::{ShaderOp, ShaderRegistry}; |
| 36 | 36 | |
| ... | ... | @@ -240,10 +240,24 @@ impl Engine { |
| 240 | 240 | self.media.set_budget_mb(budget_mb); |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | fn clear_bind_group_caches(&self) { | |
| 244 | self.pipelines.borrow_mut().clear_bind_group_cache(); | |
| 245 | if let Some(r) = self.pipelines_int16.get() { | |
| 246 | r.borrow_mut().clear_bind_group_cache(); | |
| 247 | } | |
| 248 | if let Some(r) = self.pipelines_f16.get() { | |
| 249 | r.borrow_mut().clear_bind_group_cache(); | |
| 250 | } | |
| 251 | if let Some(r) = self.pipelines_f32.get() { | |
| 252 | r.borrow_mut().clear_bind_group_cache(); | |
| 253 | } | |
| 254 | } | |
| 255 | ||
| 243 | 256 | pub fn bust_all_caches(&mut self) { |
| 244 | 257 | self.output_cache.clear(); |
| 245 | 258 | self.sync_node_cache_budget(); |
| 246 | 259 | self.cache.bust_all(); |
| 260 | self.clear_bind_group_caches(); | |
| 247 | 261 | self.media.clear(); |
| 248 | 262 | self.particles.clear(); |
| 249 | 263 | self.sprite_cache.clear(); |
| ... | ... | @@ -258,6 +272,7 @@ impl Engine { |
| 258 | 272 | self.output_cache.clear(); |
| 259 | 273 | self.sync_node_cache_budget(); |
| 260 | 274 | self.cache.bust_all(); |
| 275 | self.clear_bind_group_caches(); | |
| 261 | 276 | self.sprite_cache.clear(); |
| 262 | 277 | self.scene3d.clear_shadow_targets(); |
| 263 | 278 | *self.ram_upload_tex.borrow_mut() = None; |
| ... | ... | @@ -266,12 +281,14 @@ impl Engine { |
| 266 | 281 | pub fn bust_frame(&mut self, frame: i64) -> usize { |
| 267 | 282 | self.output_cache.clear(); |
| 268 | 283 | self.sync_node_cache_budget(); |
| 284 | self.clear_bind_group_caches(); | |
| 269 | 285 | self.cache.bust_frame(frame) |
| 270 | 286 | } |
| 271 | 287 | |
| 272 | 288 | pub fn bust_subtree(&mut self, node: NodeId) -> usize { |
| 273 | 289 | self.output_cache.clear(); |
| 274 | 290 | self.sync_node_cache_budget(); |
| 291 | self.clear_bind_group_caches(); | |
| 275 | 292 | self.cache.bust_subtree(node) |
| 276 | 293 | } |
| 277 | 294 | |
| ... | ... | @@ -332,6 +349,8 @@ impl Engine { |
| 332 | 349 | tex = self.crop_to_canvas(&mut encoder, tex); |
| 333 | 350 | } |
| 334 | 351 | self.queue.submit(Some(encoder.finish())); |
| 352 | #[cfg(not(target_arch = "wasm32"))] | |
| 353 | self.media.flush_upload_staging_after_submit(&self.device); | |
| 335 | 354 | self.finish_frame_scratch(visiting); |
| 336 | 355 | self.cache.flush_pending_pool(); |
| 337 | 356 | self.output_cache_insert(out_key, tex.clone(), stats.unsupported_nodes.clone()); |
| ... | ... | @@ -402,6 +421,8 @@ impl Engine { |
| 402 | 421 | ); |
| 403 | 422 | |
| 404 | 423 | self.queue.submit(Some(encoder.finish())); |
| 424 | #[cfg(not(target_arch = "wasm32"))] | |
| 425 | self.media.flush_upload_staging_after_submit(&self.device); | |
| 405 | 426 | if let Some(visiting) = visiting_opt { |
| 406 | 427 | self.finish_frame_scratch(visiting); |
| 407 | 428 | self.output_cache_insert(out_key, tex, stats.unsupported_nodes.clone()); |
crates/engine/src/export.rs+149-55| ... | ... | @@ -307,6 +307,7 @@ pub fn export_saver_png_sequence_with_progress( |
| 307 | 307 | |
| 308 | 308 | let mut loop_err: Option<String> = None; |
| 309 | 309 | const PREFETCH_LOOKAHEAD: usize = 12; |
| 310 | engine.prewarm_core_pipelines(); | |
| 310 | 311 | engine.media.preload_frame_loaders_with_proxy( |
| 311 | 312 | comp, |
| 312 | 313 | target, |
| ... | ... | @@ -326,6 +327,9 @@ pub fn export_saver_png_sequence_with_progress( |
| 326 | 327 | engine.use_proxy_clips, |
| 327 | 328 | ); |
| 328 | 329 | } |
| 330 | // Double-buffered async GPU readback: frame N+1 evaluates/submits on GPU while | |
| 331 | // frame N finishes its copy/map and hands off to the background PNG writer pool. | |
| 332 | let mut pending: Option<(crate::eval::PendingReadback, i64, usize, PathBuf, [u32; 2], f64)> = None; | |
| 329 | 333 | for (idx, frame) in (start..=end).enumerate() { |
| 330 | 334 | if failed.load(Ordering::Acquire) { |
| 331 | 335 | break; |
| ... | ... | @@ -355,48 +359,98 @@ pub fn export_saver_png_sequence_with_progress( |
| 355 | 359 | }; |
| 356 | 360 | |
| 357 | 361 | let (tex, stats) = engine.evaluate(comp, target, frame as f64); |
| 358 | let pixels = match engine.readback_rgba(&tex) { | |
| 359 | Ok(px) => px, | |
| 362 | let next_rb = match engine.begin_readback_rgba(&tex) { | |
| 363 | Ok(rb) => rb, | |
| 360 | 364 | Err(e) => { |
| 361 | 365 | loop_err = Some(format!("GPU readback failed at frame {frame}: {e}")); |
| 362 | 366 | break; |
| 363 | 367 | } |
| 364 | 368 | }; |
| 365 | if control.is_some_and(ExportControl::is_cancelled) { | |
| 366 | cancelled.store(true, Ordering::Release); | |
| 367 | break; | |
| 368 | } | |
| 369 | ||
| 370 | if first_path.is_none() { | |
| 371 | first_path = Some(out_path.clone()); | |
| 372 | } | |
| 373 | last_path = Some(out_path.clone()); | |
| 374 | ||
| 375 | let prog = make_progress( | |
| 376 | frame, | |
| 377 | idx, | |
| 378 | total, | |
| 379 | stats.eval_ms, | |
| 380 | out_path.clone(), | |
| 381 | saver.name.clone(), | |
| 382 | t0, | |
| 383 | ); | |
| 384 | if let Some(ctrl) = control { | |
| 385 | ctrl.update_progress(&prog); | |
| 386 | } | |
| 387 | on_progress(&prog); | |
| 388 | ||
| 389 | if tx | |
| 390 | .send(EncodeJob { | |
| 391 | path: out_path, | |
| 392 | size: tex.size, | |
| 393 | pixels, | |
| 394 | }) | |
| 395 | .is_err() | |
| 369 | if let Some((prev_rb, prev_frame, prev_idx, prev_path, prev_size, prev_ms)) = | |
| 370 | pending.replace((next_rb, frame, idx, out_path, tex.size, stats.eval_ms)) | |
| 396 | 371 | { |
| 397 | break; | |
| 372 | let pixels = match prev_rb.finish(engine) { | |
| 373 | Ok(px) => px, | |
| 374 | Err(e) => { | |
| 375 | loop_err = Some(format!("GPU readback failed at frame {prev_frame}: {e}")); | |
| 376 | break; | |
| 377 | } | |
| 378 | }; | |
| 379 | if control.is_some_and(ExportControl::is_cancelled) { | |
| 380 | cancelled.store(true, Ordering::Release); | |
| 381 | break; | |
| 382 | } | |
| 383 | if first_path.is_none() { | |
| 384 | first_path = Some(prev_path.clone()); | |
| 385 | } | |
| 386 | last_path = Some(prev_path.clone()); | |
| 387 | let prog = make_progress( | |
| 388 | prev_frame, | |
| 389 | prev_idx, | |
| 390 | total, | |
| 391 | prev_ms, | |
| 392 | prev_path.clone(), | |
| 393 | saver.name.clone(), | |
| 394 | t0, | |
| 395 | ); | |
| 396 | if let Some(ctrl) = control { | |
| 397 | ctrl.update_progress(&prog); | |
| 398 | } | |
| 399 | on_progress(&prog); | |
| 400 | if tx | |
| 401 | .send(EncodeJob { | |
| 402 | path: prev_path, | |
| 403 | size: prev_size, | |
| 404 | pixels, | |
| 405 | }) | |
| 406 | .is_err() | |
| 407 | { | |
| 408 | break; | |
| 409 | } | |
| 410 | frames_written += 1; | |
| 411 | } | |
| 412 | } | |
| 413 | if loop_err.is_none() && !failed.load(Ordering::Acquire) && !cancelled.load(Ordering::Acquire) { | |
| 414 | if let Some((prev_rb, prev_frame, prev_idx, prev_path, prev_size, prev_ms)) = pending.take() { | |
| 415 | match prev_rb.finish(engine) { | |
| 416 | Ok(pixels) => { | |
| 417 | if control.is_some_and(ExportControl::is_cancelled) { | |
| 418 | cancelled.store(true, Ordering::Release); | |
| 419 | } else { | |
| 420 | if first_path.is_none() { | |
| 421 | first_path = Some(prev_path.clone()); | |
| 422 | } | |
| 423 | last_path = Some(prev_path.clone()); | |
| 424 | let prog = make_progress( | |
| 425 | prev_frame, | |
| 426 | prev_idx, | |
| 427 | total, | |
| 428 | prev_ms, | |
| 429 | prev_path.clone(), | |
| 430 | saver.name.clone(), | |
| 431 | t0, | |
| 432 | ); | |
| 433 | if let Some(ctrl) = control { | |
| 434 | ctrl.update_progress(&prog); | |
| 435 | } | |
| 436 | on_progress(&prog); | |
| 437 | if tx | |
| 438 | .send(EncodeJob { | |
| 439 | path: prev_path, | |
| 440 | size: prev_size, | |
| 441 | pixels, | |
| 442 | }) | |
| 443 | .is_ok() | |
| 444 | { | |
| 445 | frames_written += 1; | |
| 446 | } | |
| 447 | } | |
| 448 | } | |
| 449 | Err(e) => { | |
| 450 | loop_err = Some(format!("GPU readback failed at frame {prev_frame}: {e}")); | |
| 451 | } | |
| 452 | } | |
| 398 | 453 | } |
| 399 | frames_written += 1; | |
| 400 | 454 | } |
| 401 | 455 | |
| 402 | 456 | drop(prefetch); |
| ... | ... | @@ -935,6 +989,7 @@ pub fn export_node_video_ffmpeg_with_progress( |
| 935 | 989 | engine.use_proxy_clips, |
| 936 | 990 | ); |
| 937 | 991 | } |
| 992 | let mut pending: Option<(crate::eval::PendingReadback, i64, usize, [u32; 2], f64)> = None; | |
| 938 | 993 | for (idx, frame) in ((start + 1)..=end).enumerate() { |
| 939 | 994 | if writer_failed.load(Ordering::Acquire) { |
| 940 | 995 | break; |
| ... | ... | @@ -956,33 +1011,72 @@ pub fn export_node_video_ffmpeg_with_progress( |
| 956 | 1011 | ); |
| 957 | 1012 | } |
| 958 | 1013 | let (tex, stats) = engine.evaluate(comp, opts.target, frame as f64); |
| 959 | let pixels = match engine.readback_rgba(&tex) { | |
| 960 | Ok(px) => px, | |
| 1014 | let next_rb = match engine.begin_readback_rgba(&tex) { | |
| 1015 | Ok(rb) => rb, | |
| 961 | 1016 | Err(e) => { |
| 962 | 1017 | pipe_err = Some(format!("GPU readback failed at frame {frame}: {e}")); |
| 963 | 1018 | break; |
| 964 | 1019 | } |
| 965 | 1020 | }; |
| 966 | if control.is_some_and(ExportControl::is_cancelled) { | |
| 967 | cancelled = true; | |
| 968 | break; | |
| 969 | } | |
| 970 | if tx.send((frame, tex.size, pixels)).is_err() { | |
| 971 | break; | |
| 1021 | if let Some((prev_rb, prev_frame, prev_idx, prev_size, prev_ms)) = | |
| 1022 | pending.replace((next_rb, frame, idx, tex.size, stats.eval_ms)) | |
| 1023 | { | |
| 1024 | let pixels = match prev_rb.finish(engine) { | |
| 1025 | Ok(px) => px, | |
| 1026 | Err(e) => { | |
| 1027 | pipe_err = Some(format!("GPU readback failed at frame {prev_frame}: {e}")); | |
| 1028 | break; | |
| 1029 | } | |
| 1030 | }; | |
| 1031 | if control.is_some_and(ExportControl::is_cancelled) { | |
| 1032 | cancelled = true; | |
| 1033 | break; | |
| 1034 | } | |
| 1035 | if tx.send((prev_frame, prev_size, pixels)).is_err() { | |
| 1036 | break; | |
| 1037 | } | |
| 1038 | let prog = make_progress( | |
| 1039 | prev_frame, | |
| 1040 | prev_idx + 1, | |
| 1041 | total, | |
| 1042 | prev_ms, | |
| 1043 | opts.out_path.clone(), | |
| 1044 | node_name.clone(), | |
| 1045 | t0, | |
| 1046 | ); | |
| 1047 | if let Some(ctrl) = control { | |
| 1048 | ctrl.update_progress(&prog); | |
| 1049 | } | |
| 1050 | on_progress(prog); | |
| 972 | 1051 | } |
| 973 | let prog = make_progress( | |
| 974 | frame, | |
| 975 | idx + 1, | |
| 976 | total, | |
| 977 | stats.eval_ms, | |
| 978 | opts.out_path.clone(), | |
| 979 | node_name.clone(), | |
| 980 | t0, | |
| 981 | ); | |
| 982 | if let Some(ctrl) = control { | |
| 983 | ctrl.update_progress(&prog); | |
| 1052 | } | |
| 1053 | if pipe_err.is_none() && !cancelled && !writer_failed.load(Ordering::Acquire) { | |
| 1054 | if let Some((prev_rb, prev_frame, prev_idx, prev_size, prev_ms)) = pending.take() { | |
| 1055 | match prev_rb.finish(engine) { | |
| 1056 | Ok(pixels) => { | |
| 1057 | if control.is_some_and(ExportControl::is_cancelled) { | |
| 1058 | cancelled = true; | |
| 1059 | } else if tx.send((prev_frame, prev_size, pixels)).is_ok() { | |
| 1060 | let prog = make_progress( | |
| 1061 | prev_frame, | |
| 1062 | prev_idx + 1, | |
| 1063 | total, | |
| 1064 | prev_ms, | |
| 1065 | opts.out_path.clone(), | |
| 1066 | node_name.clone(), | |
| 1067 | t0, | |
| 1068 | ); | |
| 1069 | if let Some(ctrl) = control { | |
| 1070 | ctrl.update_progress(&prog); | |
| 1071 | } | |
| 1072 | on_progress(prog); | |
| 1073 | } | |
| 1074 | } | |
| 1075 | Err(e) => { | |
| 1076 | pipe_err = Some(format!("GPU readback failed at frame {prev_frame}: {e}")); | |
| 1077 | } | |
| 1078 | } | |
| 984 | 1079 | } |
| 985 | on_progress(prog); | |
| 986 | 1080 | } |
| 987 | 1081 | drop(prefetch); |
| 988 | 1082 | } |
crates/engine/src/lib.rs+1-1| ... | ... | @@ -20,7 +20,7 @@ pub use cache::{ |
| 20 | 20 | CacheMode, CachedTexture, DEFAULT_VRAM_BUDGET_MB, EvalStats, GpuCache, NodeCache, TexturePool, |
| 21 | 21 | TexturePoolKey, TexturePoolStats, |
| 22 | 22 | }; |
| 23 | pub use eval::{DisplaySettings, Engine, create_texture}; | |
| 23 | pub use eval::{DisplaySettings, Engine, PendingReadback, create_texture}; | |
| 24 | 24 | #[cfg(not(target_arch = "wasm32"))] |
| 25 | 25 | pub use export::{ExportOptions, ExportProgress, ExportSummary, export_saver_png_sequence, select_saver}; |
| 26 | 26 | pub use profile::{FrameProfile, NodeProfileEntry}; |
crates/engine/src/media.rs+10| ... | ... | @@ -621,6 +621,16 @@ impl MediaCache { |
| 621 | 621 | .finish_upload(buffer); |
| 622 | 622 | } |
| 623 | 623 | |
| 624 | /// Marks submitted upload staging buffers ready to begin asynchronous write-mapping | |
| 625 | /// immediately after `queue.submit`, so they are already mapped by the next frame. | |
| 626 | #[cfg(not(target_arch = "wasm32"))] | |
| 627 | pub(crate) fn flush_upload_staging_after_submit(&self, device: &wgpu::Device) { | |
| 628 | if let Ok(mut pool) = self.staging_pool.lock() { | |
| 629 | pool.mark_frame_start(); | |
| 630 | pool.flush_pending_if_needed(device); | |
| 631 | } | |
| 632 | } | |
| 633 | ||
| 624 | 634 | pub fn set_budget_mb(&mut self, budget_mb: u64) { |
| 625 | 635 | let Ok(mut state) = self.shared.state.lock() else { return }; |
| 626 | 636 | state.budget_bytes = budget_mb.saturating_mul(1024 * 1024); |