Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix DirectX atlas panic after GPU device recovery (#55878)
Ben Brandt7d19e899889f
diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rsindex dc387c67f39..46b1ab64a18 100644--- a/crates/gpui/src/window.rs+++ b/crates/gpui/src/window.rs@@ -1402,6 +1402,11 @@ impl Window {measure("frame duration", || {handle.update(&mut cx, |_, window, cx| {+ if request_frame_options.force_render {+ // Bypass cached view reuse so we don't replay stale+ // atlas tile references after a GPU device recovery.+ window.refresh();+ }let arena_clear_needed = window.draw(cx);window.present();arena_clear_needed.clear();diff --git a/crates/gpui_windows/src/events.rs b/crates/gpui_windows/src/events.rsindex a4c47789191..77c4cde9788 100644--- a/crates/gpui_windows/src/events.rs+++ b/crates/gpui_windows/src/events.rs@@ -1174,6 +1174,11 @@ impl WindowsWindowInner {{panic!("Device lost: {err}");}+ // Make sure the first `draw_window` after recovery (whether it comes+ // from the forced WM_GPUI_FORCE_UPDATE_WINDOW or a stray WM_PAINT in+ // between) is treated as a forced render so it both clears+ // `skip_draws` and bypasses the view cache.+ self.state.force_render_after_recovery.set(true);Some(0)}@@ -1198,6 +1203,7 @@ impl WindowsWindowInner {}}+ let force_render = force_render || self.state.force_render_after_recovery.take();if force_render {// Re-enable drawing after a device loss recovery. The forced render// will rebuild the scene with fresh atlas textures.diff --git a/crates/gpui_windows/src/window.rs b/crates/gpui_windows/src/window.rsindex 130d3dd7214..178d750024f 100644--- a/crates/gpui_windows/src/window.rs+++ b/crates/gpui_windows/src/window.rs@@ -63,6 +63,12 @@ pub struct WindowsWindowState {pub direct_manipulation: DirectManipulationHandler,pub renderer: RefCell<DirectXRenderer>,+ /// Set after a GPU device-lost recovery so the next `draw_window` call is+ /// treated as a forced render. This guarantees the next frame both+ /// re-enables drawing (via `mark_drawable`) and bypasses the GPUI view+ /// cache, which would otherwise replay stale atlas tile references from+ /// the previous frame and panic in `DirectXAtlasState::texture`.+ pub force_render_after_recovery: Cell<bool>,pub click_state: ClickState,pub current_cursor: Cell<Option<HCURSOR>>,@@ -159,6 +165,7 @@ impl WindowsWindowState {last_reported_capslock: Cell::new(last_reported_capslock),hovered: Cell::new(hovered),renderer: RefCell::new(renderer),+ force_render_after_recovery: Cell::new(false),click_state,current_cursor: Cell::new(current_cursor),cursor_visible,