| 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,6 +244,7 @@ fn run_batch_render( |
| 244 | 244 | ||
| 245 | let mut loop_err: Option<String> = None; | 245 | let mut loop_err: Option<String> = None; |
| 246 | const PREFETCH_LOOKAHEAD: usize = 12; | 246 | const PREFETCH_LOOKAHEAD: usize = 12; |
| 247 | engine.prewarm_core_pipelines(); | ||
| 247 | engine.media.preload_frame_loaders_with_proxy( | 248 | engine.media.preload_frame_loaders_with_proxy( |
| 248 | &comp, | 249 | &comp, |
| 249 | target, | 250 | target, |
| ... | @@ -263,6 +264,7 @@ fn run_batch_render( | ... | @@ -263,6 +264,7 @@ fn run_batch_render( |
| 263 | engine.use_proxy_clips, | 264 | engine.use_proxy_clips, |
| 264 | ); | 265 | ); |
| 265 | } | 266 | } |
| 267 | let mut pending: Option<(engine::PendingReadback, i64, usize, [u32; 2], engine::EvalStats)> = None; | ||
| 266 | for (idx, f) in (start..=end).enumerate() { | 268 | for (idx, f) in (start..=end).enumerate() { |
| 267 | if failed.load(Ordering::Acquire) { | 269 | if failed.load(Ordering::Acquire) { |
| 268 | break; | 270 | break; |
| ... | @@ -280,34 +282,73 @@ fn run_batch_render( | ... | @@ -280,34 +282,73 @@ fn run_batch_render( |
| 280 | ); | 282 | ); |
| 281 | } | 283 | } |
| 282 | let (tex, stats) = engine.evaluate(&comp, target, f as f64); | 284 | let (tex, stats) = engine.evaluate(&comp, target, f as f64); |
| 283 | let pixels = match engine.readback_rgba(&tex) { | 285 | let next_rb = match engine.begin_readback_rgba(&tex) { |
| 284 | Ok(px) => px, | 286 | Ok(rb) => rb, |
| 285 | Err(e) => { | 287 | Err(e) => { |
| 286 | loop_err = Some(format!("GPU readback failed at frame {f}: {e}")); | 288 | loop_err = Some(format!("GPU readback failed at frame {f}: {e}")); |
| 287 | break; | 289 | break; |
| 288 | } | 290 | } |
| 289 | }; | 291 | }; |
| 290 | let out_file = out_dir.join(format!("{f:04}.png")); | 292 | if let Some((prev_rb, prev_f, prev_idx, prev_size, prev_stats)) = |
| 291 | if tx | 293 | pending.replace((next_rb, f, idx, tex.size, stats)) |
| 292 | .send(RenderEncodeJob { | ||
| 293 | path: out_file, | ||
| 294 | size: tex.size, | ||
| 295 | pixels, | ||
| 296 | }) | ||
| 297 | .is_err() | ||
| 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 { | 325 | } |
| 302 | let elapsed = t_all.elapsed().as_secs_f64().max(1e-6); | 326 | if loop_err.is_none() && !failed.load(Ordering::Acquire) { |
| 303 | let fps = (idx + 1) as f64 / elapsed; | 327 | if let Some((prev_rb, prev_f, prev_idx, prev_size, prev_stats)) = pending.take() { |
| 304 | eprintln!( | 328 | match prev_rb.finish(&engine) { |
| 305 | " [{:>4}/{total}] f{f:04} | eval={:.1}ms | avg={fps:.1} fps | vram={:.0}MB | unsupported={:?}", | 329 | Ok(pixels) => { |
| 306 | idx + 1, | 330 | let out_file = out_dir.join(format!("{prev_f:04}.png")); |
| 307 | stats.eval_ms, | 331 | let _ = tx.send(RenderEncodeJob { |
| 308 | stats.cached_vram_mb, | 332 | path: out_file, |
| 309 | stats.unsupported_nodes, | 333 | size: prev_size, |
| 310 | ); | 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,7 +30,7 @@ mod dispatch; |
| 30 | mod output_cache; | 30 | mod output_cache; |
| 31 | 31 | ||
| 32 | use dispatch::UniformParams; | 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 | use output_cache::OutputCache; | 34 | use output_cache::OutputCache; |
| 35 | use registry::{ShaderOp, ShaderRegistry}; | 35 | use registry::{ShaderOp, ShaderRegistry}; |
| 36 | 36 | ||
| ... | @@ -240,10 +240,24 @@ impl Engine { | ... | @@ -240,10 +240,24 @@ impl Engine { |
| 240 | self.media.set_budget_mb(budget_mb); | 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 | pub fn bust_all_caches(&mut self) { | 256 | pub fn bust_all_caches(&mut self) { |
| 244 | self.output_cache.clear(); | 257 | self.output_cache.clear(); |
| 245 | self.sync_node_cache_budget(); | 258 | self.sync_node_cache_budget(); |
| 246 | self.cache.bust_all(); | 259 | self.cache.bust_all(); |
| 260 | self.clear_bind_group_caches(); | ||
| 247 | self.media.clear(); | 261 | self.media.clear(); |
| 248 | self.particles.clear(); | 262 | self.particles.clear(); |
| 249 | self.sprite_cache.clear(); | 263 | self.sprite_cache.clear(); |
| ... | @@ -258,6 +272,7 @@ impl Engine { | ... | @@ -258,6 +272,7 @@ impl Engine { |
| 258 | self.output_cache.clear(); | 272 | self.output_cache.clear(); |
| 259 | self.sync_node_cache_budget(); | 273 | self.sync_node_cache_budget(); |
| 260 | self.cache.bust_all(); | 274 | self.cache.bust_all(); |
| 275 | self.clear_bind_group_caches(); | ||
| 261 | self.sprite_cache.clear(); | 276 | self.sprite_cache.clear(); |
| 262 | self.scene3d.clear_shadow_targets(); | 277 | self.scene3d.clear_shadow_targets(); |
| 263 | *self.ram_upload_tex.borrow_mut() = None; | 278 | *self.ram_upload_tex.borrow_mut() = None; |
| ... | @@ -266,12 +281,14 @@ impl Engine { | ... | @@ -266,12 +281,14 @@ impl Engine { |
| 266 | pub fn bust_frame(&mut self, frame: i64) -> usize { | 281 | pub fn bust_frame(&mut self, frame: i64) -> usize { |
| 267 | self.output_cache.clear(); | 282 | self.output_cache.clear(); |
| 268 | self.sync_node_cache_budget(); | 283 | self.sync_node_cache_budget(); |
| 284 | self.clear_bind_group_caches(); | ||
| 269 | self.cache.bust_frame(frame) | 285 | self.cache.bust_frame(frame) |
| 270 | } | 286 | } |
| 271 | 287 | ||
| 272 | pub fn bust_subtree(&mut self, node: NodeId) -> usize { | 288 | pub fn bust_subtree(&mut self, node: NodeId) -> usize { |
| 273 | self.output_cache.clear(); | 289 | self.output_cache.clear(); |
| 274 | self.sync_node_cache_budget(); | 290 | self.sync_node_cache_budget(); |
| 291 | self.clear_bind_group_caches(); | ||
| 275 | self.cache.bust_subtree(node) | 292 | self.cache.bust_subtree(node) |
| 276 | } | 293 | } |
| 277 | 294 | ||
| ... | @@ -332,6 +349,8 @@ impl Engine { | ... | @@ -332,6 +349,8 @@ impl Engine { |
| 332 | tex = self.crop_to_canvas(&mut encoder, tex); | 349 | tex = self.crop_to_canvas(&mut encoder, tex); |
| 333 | } | 350 | } |
| 334 | self.queue.submit(Some(encoder.finish())); | 351 | self.queue.submit(Some(encoder.finish())); |
| 352 | #[cfg(not(target_arch = "wasm32"))] | ||
| 353 | self.media.flush_upload_staging_after_submit(&self.device); | ||
| 335 | self.finish_frame_scratch(visiting); | 354 | self.finish_frame_scratch(visiting); |
| 336 | self.cache.flush_pending_pool(); | 355 | self.cache.flush_pending_pool(); |
| 337 | self.output_cache_insert(out_key, tex.clone(), stats.unsupported_nodes.clone()); | 356 | self.output_cache_insert(out_key, tex.clone(), stats.unsupported_nodes.clone()); |
| ... | @@ -402,6 +421,8 @@ impl Engine { | ... | @@ -402,6 +421,8 @@ impl Engine { |
| 402 | ); | 421 | ); |
| 403 | 422 | ||
| 404 | self.queue.submit(Some(encoder.finish())); | 423 | self.queue.submit(Some(encoder.finish())); |
| 424 | #[cfg(not(target_arch = "wasm32"))] | ||
| 425 | self.media.flush_upload_staging_after_submit(&self.device); | ||
| 405 | if let Some(visiting) = visiting_opt { | 426 | if let Some(visiting) = visiting_opt { |
| 406 | self.finish_frame_scratch(visiting); | 427 | self.finish_frame_scratch(visiting); |
| 407 | self.output_cache_insert(out_key, tex, stats.unsupported_nodes.clone()); | 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,6 +307,7 @@ pub fn export_saver_png_sequence_with_progress( |
| 307 | 307 | ||
| 308 | let mut loop_err: Option<String> = None; | 308 | let mut loop_err: Option<String> = None; |
| 309 | const PREFETCH_LOOKAHEAD: usize = 12; | 309 | const PREFETCH_LOOKAHEAD: usize = 12; |
| 310 | engine.prewarm_core_pipelines(); | ||
| 310 | engine.media.preload_frame_loaders_with_proxy( | 311 | engine.media.preload_frame_loaders_with_proxy( |
| 311 | comp, | 312 | comp, |
| 312 | target, | 313 | target, |
| ... | @@ -326,6 +327,9 @@ pub fn export_saver_png_sequence_with_progress( | ... | @@ -326,6 +327,9 @@ pub fn export_saver_png_sequence_with_progress( |
| 326 | engine.use_proxy_clips, | 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 | for (idx, frame) in (start..=end).enumerate() { | 333 | for (idx, frame) in (start..=end).enumerate() { |
| 330 | if failed.load(Ordering::Acquire) { | 334 | if failed.load(Ordering::Acquire) { |
| 331 | break; | 335 | break; |
| ... | @@ -355,48 +359,98 @@ pub fn export_saver_png_sequence_with_progress( | ... | @@ -355,48 +359,98 @@ pub fn export_saver_png_sequence_with_progress( |
| 355 | }; | 359 | }; |
| 356 | 360 | ||
| 357 | let (tex, stats) = engine.evaluate(comp, target, frame as f64); | 361 | let (tex, stats) = engine.evaluate(comp, target, frame as f64); |
| 358 | let pixels = match engine.readback_rgba(&tex) { | 362 | let next_rb = match engine.begin_readback_rgba(&tex) { |
| 359 | Ok(px) => px, | 363 | Ok(rb) => rb, |
| 360 | Err(e) => { | 364 | Err(e) => { |
| 361 | loop_err = Some(format!("GPU readback failed at frame {frame}: {e}")); | 365 | loop_err = Some(format!("GPU readback failed at frame {frame}: {e}")); |
| 362 | break; | 366 | break; |
| 363 | } | 367 | } |
| 364 | }; | 368 | }; |
| 365 | if control.is_some_and(ExportControl::is_cancelled) { | 369 | if let Some((prev_rb, prev_frame, prev_idx, prev_path, prev_size, prev_ms)) = |
| 366 | cancelled.store(true, Ordering::Release); | 370 | pending.replace((next_rb, frame, idx, out_path, tex.size, stats.eval_ms)) |
| 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() | ||
| 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 | drop(prefetch); | 456 | drop(prefetch); |
| ... | @@ -935,6 +989,7 @@ pub fn export_node_video_ffmpeg_with_progress( | ... | @@ -935,6 +989,7 @@ pub fn export_node_video_ffmpeg_with_progress( |
| 935 | engine.use_proxy_clips, | 989 | engine.use_proxy_clips, |
| 936 | ); | 990 | ); |
| 937 | } | 991 | } |
| 992 | let mut pending: Option<(crate::eval::PendingReadback, i64, usize, [u32; 2], f64)> = None; | ||
| 938 | for (idx, frame) in ((start + 1)..=end).enumerate() { | 993 | for (idx, frame) in ((start + 1)..=end).enumerate() { |
| 939 | if writer_failed.load(Ordering::Acquire) { | 994 | if writer_failed.load(Ordering::Acquire) { |
| 940 | break; | 995 | break; |
| ... | @@ -956,33 +1011,72 @@ pub fn export_node_video_ffmpeg_with_progress( | ... | @@ -956,33 +1011,72 @@ pub fn export_node_video_ffmpeg_with_progress( |
| 956 | ); | 1011 | ); |
| 957 | } | 1012 | } |
| 958 | let (tex, stats) = engine.evaluate(comp, opts.target, frame as f64); | 1013 | let (tex, stats) = engine.evaluate(comp, opts.target, frame as f64); |
| 959 | let pixels = match engine.readback_rgba(&tex) { | 1014 | let next_rb = match engine.begin_readback_rgba(&tex) { |
| 960 | Ok(px) => px, | 1015 | Ok(rb) => rb, |
| 961 | Err(e) => { | 1016 | Err(e) => { |
| 962 | pipe_err = Some(format!("GPU readback failed at frame {frame}: {e}")); | 1017 | pipe_err = Some(format!("GPU readback failed at frame {frame}: {e}")); |
| 963 | break; | 1018 | break; |
| 964 | } | 1019 | } |
| 965 | }; | 1020 | }; |
| 966 | if control.is_some_and(ExportControl::is_cancelled) { | 1021 | if let Some((prev_rb, prev_frame, prev_idx, prev_size, prev_ms)) = |
| 967 | cancelled = true; | 1022 | pending.replace((next_rb, frame, idx, tex.size, stats.eval_ms)) |
| 968 | break; | 1023 | { |
| 969 | } | 1024 | let pixels = match prev_rb.finish(engine) { |
| 970 | if tx.send((frame, tex.size, pixels)).is_err() { | 1025 | Ok(px) => px, |
| 971 | break; | 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( | 1052 | } |
| 974 | frame, | 1053 | if pipe_err.is_none() && !cancelled && !writer_failed.load(Ordering::Acquire) { |
| 975 | idx + 1, | 1054 | if let Some((prev_rb, prev_frame, prev_idx, prev_size, prev_ms)) = pending.take() { |
| 976 | total, | 1055 | match prev_rb.finish(engine) { |
| 977 | stats.eval_ms, | 1056 | Ok(pixels) => { |
| 978 | opts.out_path.clone(), | 1057 | if control.is_some_and(ExportControl::is_cancelled) { |
| 979 | node_name.clone(), | 1058 | cancelled = true; |
| 980 | t0, | 1059 | } else if tx.send((prev_frame, prev_size, pixels)).is_ok() { |
| 981 | ); | 1060 | let prog = make_progress( |
| 982 | if let Some(ctrl) = control { | 1061 | prev_frame, |
| 983 | ctrl.update_progress(&prog); | 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 | drop(prefetch); | 1081 | drop(prefetch); |
| 988 | } | 1082 | } |
crates/engine/src/lib.rs+1-1| ... | @@ -20,7 +20,7 @@ pub use cache::{ | ... | @@ -20,7 +20,7 @@ pub use cache::{ |
| 20 | CacheMode, CachedTexture, DEFAULT_VRAM_BUDGET_MB, EvalStats, GpuCache, NodeCache, TexturePool, | 20 | CacheMode, CachedTexture, DEFAULT_VRAM_BUDGET_MB, EvalStats, GpuCache, NodeCache, TexturePool, |
| 21 | TexturePoolKey, TexturePoolStats, | 21 | TexturePoolKey, TexturePoolStats, |
| 22 | }; | 22 | }; |
| 23 | pub use eval::{DisplaySettings, Engine, create_texture}; | 23 | pub use eval::{DisplaySettings, Engine, PendingReadback, create_texture}; |
| 24 | #[cfg(not(target_arch = "wasm32"))] | 24 | #[cfg(not(target_arch = "wasm32"))] |
| 25 | pub use export::{ExportOptions, ExportProgress, ExportSummary, export_saver_png_sequence, select_saver}; | 25 | pub use export::{ExportOptions, ExportProgress, ExportSummary, export_saver_png_sequence, select_saver}; |
| 26 | pub use profile::{FrameProfile, NodeProfileEntry}; | 26 | pub use profile::{FrameProfile, NodeProfileEntry}; |
crates/engine/src/media.rs+10| ... | @@ -621,6 +621,16 @@ impl MediaCache { | ... | @@ -621,6 +621,16 @@ impl MediaCache { |
| 621 | .finish_upload(buffer); | 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 | pub fn set_budget_mb(&mut self, budget_mb: u64) { | 634 | pub fn set_budget_mb(&mut self, budget_mb: u64) { |
| 625 | let Ok(mut state) = self.shared.state.lock() else { return }; | 635 | let Ok(mut state) = self.shared.state.lock() else { return }; |
| 626 | state.budget_bytes = budget_mb.saturating_mul(1024 * 1024); | 636 | state.budget_bytes = budget_mb.saturating_mul(1024 * 1024); |