Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
perf(desktop-gpui): reuse the shared wgpu device for preparing previews
LukeParkerDev6c44ca940be3
diff --git a/apps/desktop-gpui/src/editor_preparing.rs b/apps/desktop-gpui/src/editor_preparing.rsindex ad4bb57b4..92f6a5faf 100644--- a/apps/desktop-gpui/src/editor_preparing.rs+++ b/apps/desktop-gpui/src/editor_preparing.rs@@ -527,6 +527,7 @@ impl PreparingRunner {let frame_format = EditorFrameFormat::BgraSurface;#[cfg(not(target_os = "macos"))]let frame_format = EditorFrameFormat::Rgba;+ let shared_device = crate::app_windows::shared_wgpu_device().await;self.control.accepts_frames.store(true, Ordering::Release);let playback = PreparingPlaybackSession::spawn_with_expected_metadata(input,@@ -535,6 +536,7 @@ impl PreparingRunner {preview: PreparingPreviewOptions {use_hardware_decoding: preparing_hardware_decode(),frame_format,+ shared_device,},fps: crate::editor_window::EDITOR_PREVIEW_FPS,resolution: self.resolution,diff --git a/apps/desktop/src-tauri/src/editor_preparing.rs b/apps/desktop/src-tauri/src/editor_preparing.rsindex 7a213388e..74a236e13 100644--- a/apps/desktop/src-tauri/src/editor_preparing.rs+++ b/apps/desktop/src-tauri/src/editor_preparing.rs@@ -773,6 +773,7 @@ impl Runner {preview: PreparingPreviewOptions {use_hardware_decoding: !cfg!(target_os = "windows"),frame_format: EditorFrameFormat::Rgba,+ shared_device: None,},fps: crate::EDITOR_PREVIEW_FPS,resolution: crate::default_editor_preview_resolution(),diff --git a/crates/editor/src/preparing_playback.rs b/crates/editor/src/preparing_playback.rsindex 5758bbc8e..e163ae186 100644--- a/crates/editor/src/preparing_playback.rs+++ b/crates/editor/src/preparing_playback.rs@@ -20,7 +20,7 @@ pub struct PreparingAudioSegmentInput {pub timing_repair: crate::SegmentAudioTimingRepair,}-#[derive(Clone, Copy)]+#[derive(Clone)]pub struct PreparingPlaybackOptions {pub preview: crate::PreparingPreviewOptions,pub fps: u32,@@ -531,7 +531,7 @@ impl PreparingPlaybackRunner {let discard = received.clone();let preview = crate::PreparingPreview::spawn(input,- self.options.preview,+ self.options.preview.clone(),Box::new(move |request, output, layout| {deliver_latest(&frames, &discard, (request, output, layout));}),diff --git a/crates/editor/src/preparing_preview.rs b/crates/editor/src/preparing_preview.rsindex caf5bf4c8..0d57a88e6 100644--- a/crates/editor/src/preparing_preview.rs+++ b/crates/editor/src/preparing_preview.rs@@ -65,10 +65,11 @@ pub struct PreparingPreviewInput {pub cursor_assets: FrozenRecordedCursorAssets,}-#[derive(Clone, Copy, Debug, Default)]+#[derive(Clone, Debug, Default)]pub struct PreparingPreviewOptions {pub use_hardware_decoding: bool,pub frame_format: EditorFrameFormat,+ pub shared_device: Option<cap_rendering::SharedWgpuDevice>,}#[derive(Clone, Copy, Debug, PartialEq)]@@ -538,17 +539,23 @@ async fn run_preview(.camera.as_ref().map(|camera| XY::new(camera.video_width, camera.video_height));- let constants = RenderVideoConstants::new_with_options(- RenderOptions {- screen_size,- camera_size,- preserve_screen_alpha: false,- },- recording_meta,- metadata,- )- .await- .map_err(|error| PreparingPreviewError::Render(error.to_string()))?+ let render_options = RenderOptions {+ screen_size,+ camera_size,+ preserve_screen_alpha: false,+ };+ let constants = match options.shared_device {+ Some(shared) => RenderVideoConstants::from_shared_device(+ shared,+ render_options,+ metadata,+ recording_meta,+ Arc::new(cap_rendering::BackgroundTextureCache::default()),+ ),+ None => RenderVideoConstants::new_with_options(render_options, recording_meta, metadata)+ .await+ .map_err(|error| PreparingPreviewError::Render(error.to_string()))?,+ }.with_frozen_recorded_cursors(cursor_assets);control.check()?;let mut layers = RendererLayers::new_for_preparing_preview(diff --git a/crates/editor/src/preparing_preview/native_tests.rs b/crates/editor/src/preparing_preview/native_tests.rsindex 211147d86..578745b8d 100644--- a/crates/editor/src/preparing_preview/native_tests.rs+++ b/crates/editor/src/preparing_preview/native_tests.rs@@ -784,6 +784,7 @@ async fn composed_parity_with_reference(PreparingPreviewOptions {use_hardware_decoding: true,frame_format,+ shared_device: None,},Box::new(move |request, output, layout| {let frame = match output {@@ -963,6 +964,7 @@ async fn native_callback_panic_joins_workers_and_releases_source_owner() {PreparingPreviewOptions {use_hardware_decoding: true,frame_format: EditorFrameFormat::Rgba,+ shared_device: None,},Box::new(move |_, _, _| {sender.take().unwrap().send(()).unwrap();diff --git a/crates/rendering/src/lib.rs b/crates/rendering/src/lib.rsindex b17e25424..05758d1d9 100644--- a/crates/rendering/src/lib.rs+++ b/crates/rendering/src/lib.rs@@ -2246,6 +2246,7 @@ pub async fn create_shared_device() -> Result<SharedWgpuDevice, RenderingError>})}+#[derive(Clone, Debug)]pub struct SharedWgpuDevice {pub instance: wgpu::Instance,pub adapter: wgpu::Adapter,