From 30ceb9176cb751b0f4f60516a3248f4ded99b082 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Fri, 27 Feb 2026 13:24:53 -0700 Subject: [PATCH] Reduce wgpu memory usage during resize (#50030) Closes #49435 Before you mark this PR as ready for review, make sure that you have: - [ ] Added a solid test coverage and/or screenshots from doing manual testing - [ ] Done a self-review taking into account security and performance aspects - [ ] Aligned any UI changes with the [UI checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) Release Notes: - Linux: Reduced GPU memory usage during resize --- crates/gpui_wgpu/src/wgpu_renderer.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/gpui_wgpu/src/wgpu_renderer.rs b/crates/gpui_wgpu/src/wgpu_renderer.rs index 489f354c691c280a5331e5a7765c9d626064eb9c..cc416ead908830262cdae0144b4912ccf5dbc4ad 100644 --- a/crates/gpui_wgpu/src/wgpu_renderer.rs +++ b/crates/gpui_wgpu/src/wgpu_renderer.rs @@ -5,6 +5,7 @@ use gpui::{ PolychromeSprite, PrimitiveBatch, Quad, ScaledPixels, Scene, Shadow, Size, SubpixelSprite, Underline, get_gamma_correction_ratios, }; +use log::warn; #[cfg(not(target_family = "wasm"))] use raw_window_handle::{HasDisplayHandle, HasWindowHandle}; use std::num::NonZeroU64; @@ -825,6 +826,20 @@ impl WgpuRenderer { let height = size.height.0 as u32; if width != self.surface_config.width || height != self.surface_config.height { + // Wait for any in-flight GPU work to complete before destroying textures + if let Err(e) = self.device.poll(wgpu::PollType::Wait { + submission_index: None, + timeout: None, + }) { + warn!("Failed to poll device during resize: {e:?}"); + } + + // Destroy old textures before allocating new ones to avoid GPU memory spikes + self.path_intermediate_texture.destroy(); + if let Some(ref texture) = self.path_msaa_texture { + texture.destroy(); + } + self.surface_config.width = width.max(1); self.surface_config.height = height.max(1); self.surface.configure(&self.device, &self.surface_config);