Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(desktop-gpui): skip the launch warmup once an editor asks for the GPU mid-warmup and profile stages on the requested device

Richie McIlroy97d423a21842
diff --git a/apps/desktop-gpui/src/app_windows.rs b/apps/desktop-gpui/src/app_windows.rs
index 5d8a14f4d..7b793d176 100644
--- a/apps/desktop-gpui/src/app_windows.rs
+++ b/apps/desktop-gpui/src/app_windows.rs
@@ -4872,6 +4872,11 @@ pub(crate) async fn shared_wgpu_device() -> Option<cap_rendering::SharedWgpuDevi
static GPU_WORK_REQUESTED: std::sync::atomic::AtomicBool =
std::sync::atomic::AtomicBool::new(false);
+#[cfg(target_os = "macos")]
+fn gpu_work_requested() -> bool {
+ GPU_WORK_REQUESTED.load(std::sync::atomic::Ordering::Acquire)
+}
+
pub(crate) fn prewarm_shared_wgpu_device(cx: &App) {
GPU_WORK_REQUESTED.store(true, std::sync::atomic::Ordering::Release);
gpui_tokio::Tokio::spawn(cx, async {
@@ -4907,10 +4912,13 @@ pub(crate) fn schedule_launch_render_warmup(cx: &App) {
#[cfg(target_os = "macos")]
async fn warm_renderer() -> Option<f64> {
- if GPU_WORK_REQUESTED.load(std::sync::atomic::Ordering::Acquire) {
+ if gpu_work_requested() {
return None;
}
let shared = shared_wgpu_device().await?;
+ if gpu_work_requested() {
+ return None;
+ }
let started = std::time::Instant::now();
let (device, queue, software) = (
shared.device.clone(),
@@ -4918,10 +4926,14 @@ async fn warm_renderer() -> Option<f64> {
shared.is_software_adapter,
);
let mut layers = tokio::task::spawn_blocking(move || {
- cap_rendering::RendererLayers::new_with_options(&device, &queue, software)
+ (!gpu_work_requested())
+ .then(|| cap_rendering::RendererLayers::new_with_options(&device, &queue, software))
})
.await
- .ok()?;
+ .ok()??;
+ if gpu_work_requested() {
+ return None;
+ }
if let Err(error) = cap_rendering::prewarm_first_frame(shared, &mut layers).await {
tracing::warn!(%error, "launch render warmup frame failed");
}
diff --git a/crates/editor/examples/editor-startup-benchmark.rs b/crates/editor/examples/editor-startup-benchmark.rs
index 09f1fdf8a..8af88febe 100644
--- a/crates/editor/examples/editor-startup-benchmark.rs
+++ b/crates/editor/examples/editor-startup-benchmark.rs
@@ -55,6 +55,7 @@ fn push_stage(stages: &mut Vec<(&'static str, f64)>, name: &'static str, start:
async fn profile_startup_stages(
recording_path: PathBuf,
+ shared_device: Option<cap_rendering::SharedWgpuDevice>,
) -> Result<Vec<(&'static str, f64)>, String> {
let mut stages = Vec::new();
let total_start = Instant::now();
@@ -76,15 +77,23 @@ async fn profile_startup_stages(
)?);
push_stage(&mut stages, "recordings metadata", &mut stage_start);
- let render_constants = Arc::new(
+ let render_constants = Arc::new(if let Some(shared) = shared_device {
+ RenderVideoConstants::new_with_device(
+ shared,
+ &recordings.segments,
+ recording_meta.clone(),
+ (**meta).clone(),
+ )
+ .map_err(|e| format!("Failed to create render constants: {e}"))?
+ } else {
RenderVideoConstants::new(
&recordings.segments,
recording_meta.clone(),
(**meta).clone(),
)
.await
- .map_err(|e| format!("Failed to create render constants: {e}"))?,
- );
+ .map_err(|e| format!("Failed to create render constants: {e}"))?
+ });
push_stage(&mut stages, "render constants", &mut stage_start);
let layers_rx = start_renderer_layers_creation(&render_constants, &project);
@@ -112,13 +121,20 @@ async fn profile_startup_stages(
Ok(stages)
}
-async fn run_stage_profile(recording_path: PathBuf, runs: usize) {
+async fn run_stage_profile(
+ recording_path: PathBuf,
+ runs: usize,
+ shared_device: Option<&cap_rendering::SharedWgpuDevice>,
+) {
let mut stage_values: Vec<(&'static str, Vec<f64>)> = Vec::new();
for _ in 0..runs {
- let stages = profile_startup_stages(recording_path.clone())
- .await
- .expect("Failed to profile startup stages");
+ let stages = profile_startup_stages(
+ recording_path.clone(),
+ shared_device.map(clone_shared_device),
+ )
+ .await
+ .expect("Failed to profile startup stages");
for (stage_idx, (name, value)) in stages.into_iter().enumerate() {
if stage_values.len() <= stage_idx {
@@ -231,7 +247,14 @@ async fn main() {
);
}
if profile_stages_only {
- run_stage_profile(recording_path, runs).await;
+ if shared_device_mode && shared_device.is_none() {
+ shared_device = Some(
+ cap_rendering::create_shared_device()
+ .await
+ .expect("Failed to create shared device"),
+ );
+ }
+ run_stage_profile(recording_path, runs, shared_device.as_ref()).await;
return;
}
@@ -317,6 +340,6 @@ async fn main() {
);
if profile_stages {
- run_stage_profile(recording_path, runs).await;
+ run_stage_profile(recording_path, runs, shared_device.as_ref()).await;
}
}