Reduce wgpu memory usage during resize (#50030)

Conrad Irwin created

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

Change summary

crates/gpui_wgpu/src/wgpu_renderer.rs | 15 +++++++++++++++
1 file changed, 15 insertions(+)

Detailed changes

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);