EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust
Merge main into #2634; gate main's new GPU tests (ui_gpu x2, camera tracker snapshot) with gpu_test::lock
bflatasticf11fa4e5fbe2
diff --cc crates/ui-egui/tests/it/ui_camera_tracker.rsindex 1f42879a9,8c4be61a7..619d7c7c5--- a/crates/ui-egui/tests/it/ui_camera_tracker.rs+++ b/crates/ui-egui/tests/it/ui_camera_tracker.rs@@@ -146,6 -150,56 +151,57 @@@ fn viewer_points_selection_and_effect_cassert!(h.state().session.is_enabled("track.camera"));}+ #[test]+ fn blender_export_button_opens_python_dialog_and_writes_scene() {+ use effectcraft_engine::project::{Footage, FootageKind, ItemKind, LayerId, LayerSource};+ let (mut a, plate, uid) = app();+ let cid = a.session.active_comp_id().unwrap();+ a.session+ .edit("video fixture", None, |p, _| {+ let item = p.add_item(+ "Video",+ Default::default(),+ None,+ ItemKind::Footage(Footage {+ path: "/tmp/effectcraft-ui-synthetic.mp4".into(),+ kind: FootageKind::Video,+ width: W as u32,+ height: H as u32,+ has_video: true,+ duration: effectcraft_engine::time::Tick::from_seconds_f64(2.0),+ ..Default::default()+ }),+ );+ p.comp_mut(cid).unwrap().layer_mut(LayerId(plate)).unwrap().source = LayerSource::Footage { item };+ Ok(())+ })+ .unwrap();+ a.session.camera_pending.clear();+ let output = std::env::temp_dir().join(format!("effectcraft-ui-blender-{}.py", std::process::id()));+ let selected_path = output.clone();+ a.hooks.pick_save_file = Some(Box::new(move |name, ext| {+ assert!(name.ends_with(".py"));+ assert_eq!(ext, "py");+ Some(selected_path.to_string_lossy().into_owned())+ }));+ let shot = std::env::var("EFFECTCRAFT_BLENDER_UI_SNAPSHOT").ok();+ let builder = Harness::builder().with_size(egui::vec2(1600.0, 1000.0));+ let builder = if shot.is_some() { builder.wgpu() } else { builder };++ let _device = shot.is_some().then(crate::gpu_test::lock);+ let mut h = builder.build_eframe(|_| a);+ h.state_mut().show_panel(PanelKind::EffectControls);+ h.run_steps(5);+ let button = rect(&h, &format!("effectControls.cameraTracker.{uid}.exportBlender"));+ if let Some(path) = shot {+ h.render().expect("render export button").save(path).unwrap();+ }+ click(&mut h, button.center(), Default::default());+ assert!(output.exists(), "UI export failed: {}", h.state().ui.status);+ let script = std::fs::read_to_string(output).expect("clicking the export button saves a Python scene");+ assert!(script.contains("def import_scene():"));+ assert_eq!(h.state().session.active_comp().unwrap().layers.len(), 1, "export does not create a camera in the source project");+ }+/// Drag with `button` from `from` to `to` in steps, then release.fn drag_with(h: &mut Harness<'_, EffectcraftApp>, button: egui::PointerButton, from: egui::Pos2, to: egui::Pos2) {h.input_mut().events.push(egui::Event::PointerMoved(from));diff --cc crates/ui-egui/tests/it/ui_gpu.rsindex c8cdc428a,643d99492..d5d432db3--- a/crates/ui-egui/tests/it/ui_gpu.rs+++ b/crates/ui-egui/tests/it/ui_gpu.rs@@@ -19,6 -20,117 +20,119 @@@ fn settle(h: &mut Harness<'_, Effectcra}}+ /// Step until the GPU compositor's worker has handed its result over (attached, or why not).+ /// The first step starts the build.+ pub(crate) fn wait_for_compositor(h: &mut Harness<'_, EffectcraftApp>) {+ h.step();+ for _ in 0..3000 {+ if !h.state().gpu_initializing() {+ return;+ }+ h.step();+ std::thread::sleep(std::time::Duration::from_millis(20));+ }+ panic!("the GPU compositor's worker gave no result within a minute");+ }++ /// Whether wgpu finds any adapter at all (egui_kittest's wgpu harness needs one; CI runners+ /// without a GPU skip).+ fn any_adapter() -> bool {+ let instance = eframe::wgpu::Instance::new(eframe::wgpu::InstanceDescriptor::new_without_display_handle());+ !pollster::block_on(instance.enumerate_adapters(eframe::wgpu::Backends::all())).is_empty()+ }++ fn small_session() -> Session {+ let mut s = Session::default();+ let comp = s.execute("comp.new", json!({"name": "First", "width": 64, "height": 64, "duration": 1})).unwrap()["comp"].as_u64().unwrap();+ s.execute("layer.newSolid", json!({"comp": comp, "color": "#ff0000"})).unwrap();+ s+ }++ /// The window opens before the GPU compositor exists: its pipelines compile on a worker thread+ /// (tens of seconds on a cold shader cache), and until then the interface draws, says so, and+ /// composites on the CPU. The worker is held on a gate so the "preparing" state is observable.+ #[test]+ fn the_interface_draws_and_composites_on_the_cpu_while_the_gpu_compositor_is_built() {++ let _device = crate::gpu_test::lock();+ if !any_adapter() {+ eprintln!("no wgpu adapter: skipping");+ return;+ }+ let (release, gate) = std::sync::mpsc::channel::<()>();+ let s = small_session();+ let mut h = Harness::builder().with_size(egui::vec2(1200.0, 800.0)).wgpu().build_eframe(move |_| {+ let mut app = EffectcraftApp::new(s);+ // The status line's 5 s expiry reads the app clock: a manual one makes the steps below+ // stand for a known span of time.+ app.use_manual_clock();+ app.hooks.before_gpu_build = Some(Box::new(move || {+ let _ = gate.recv();+ }));+ app+ });+ // The first frames paint, and a CPU frame reaches the viewer, while the worker still waits.+ for _ in 0..600 {+ h.step();+ if h.state().is_ready() && !h.output().shapes.is_empty() && h.state().frames.last_ms.lock().map(|v| *v > 0.0).unwrap_or(false) {+ break;+ }+ std::thread::sleep(std::time::Duration::from_millis(10));+ }+ assert!(h.state().gpu_initializing(), "the compositor is still being built");+ assert!(!h.output().shapes.is_empty(), "the interface draws before the compositor exists");+ assert!(h.state().session.accel.is_none(), "nothing renders on a compositor that doesn't exist yet");+ assert_eq!(h.state().ui.status, effectcraft_ui_egui::GPU_PREPARING, "the status line is honest about it");+ assert_eq!(h.state().session.accel_note.as_deref(), Some(effectcraft_ui_egui::GPU_PREPARING));+ assert!(h.state().frames.last_ms.lock().map(|v| *v > 0.0).unwrap_or(false), "a frame was composited on the CPU meanwhile");+ assert!(h.state_mut().viewer_pixels().is_some(), "the viewer shows that frame");+ // Other statuses clear after 5 s; this one stays for as long as the build takes (each step+ // is a quarter of a second).+ for _ in 0..30 {+ h.state_mut().clock_mut().advance(0.25);+ h.step();+ }+ assert!(h.state().gpu_initializing());+ assert_eq!(h.state().ui.status, effectcraft_ui_egui::GPU_PREPARING, "the status line still says so 7.5 s later");+ release.send(()).unwrap();+ settle(&mut h);+ assert!(!h.state().gpu_initializing());+ assert_ne!(h.state().ui.status, effectcraft_ui_egui::GPU_PREPARING, "the preparing status goes away");+ match h.state().gpu_adapter() {+ Some(adapter) => {+ eprintln!("compositor attached after the first frames: {adapter}");+ assert!(h.state().session.accel.is_some());+ assert!(h.state().session.accel_note.is_none());+ }+ // An adapter that can't run the compositor (software GL): the reason is recorded.+ None => assert!(h.state().session.accel_note.as_deref().is_some_and(|n| n != effectcraft_ui_egui::GPU_PREPARING)),+ }+ }++ /// A graphics backend that panics while the compositor's pipelines compile panics on the worker+ /// thread, not under the UI: the window keeps drawing on the CPU and says why.+ #[test]+ fn a_compositor_build_that_panics_leaves_the_viewer_on_the_cpu() {++ let _device = crate::gpu_test::lock();+ if !any_adapter() {+ eprintln!("no wgpu adapter: skipping");+ return;+ }+ let s = small_session();+ let mut h = Harness::builder().with_size(egui::vec2(1200.0, 800.0)).wgpu().build_eframe(move |_| {+ let mut app = EffectcraftApp::new(s);+ app.hooks.before_gpu_build = Some(Box::new(|| panic!("synthetic shader compiler panic")));+ app+ });+ settle(&mut h);+ assert!(!h.state().gpu_initializing());+ assert!(h.state().gpu_adapter().is_none());+ assert!(h.state().session.accel.is_none());+ let note = h.state().session.accel_note.clone().unwrap_or_default();+ assert!(note.contains("synthetic shader compiler panic"), "{note}");+ assert!(!h.output().shapes.is_empty(), "the interface still draws");+ assert!(h.state_mut().viewer_pixels().is_some(), "the viewer shows a CPU frame");+ }+/// egui_kittest's wgpu setup on the adapter the headless compositor picked (`name (Backend)`),/// like the desktop app's window. Left alone, egui_kittest prefers a CPU adapter, which on/// Windows is WARP on DirectX 12, where FXC fails to compile the compositor's kernels: the