Repository navigation
fix(desktop-gpui): recover from a lost GPU device on Linux without crashing in the NVIDIA driver - #3979
Merged
Conversation
…ashing in the NVIDIA driver
|
Sandchest reviewed Sandchest reviews every change for vulnerabilities an attacker could use · 1 credit · Review details |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #3946.
On Linux with NVIDIA and Wayland, Cap crashed with a SIGSEGV at address 0 inside the NVIDIA driver after the GPU device was lost. Before the crash its windows could go permanently blank (
painted_fps=0.0in the log).Root cause
Two defects in gpui's device-lost handling on Linux.
sequenceDiagram participant W as window participant R as WgpuRenderer::recover participant D as NVIDIA driver W->>R: device lost R->>D: create instance B, surface, device R->>D: release old resources (device A and instance A destroyed) R->>D: surface query or swapchain creation on instance B D-->>W: call through a null pointer, SIGSEGV at 0WgpuRenderer::recover(gpui_wgpu/src/wgpu_renderer.rs:2286) made a new wgpu instance for the new device, then released the old one. With Wayland surfaces in use, NVIDIA's Vulkan driver does not survive a second instance being created and the first destroyed: the nextvkGetPhysicalDeviceSurfaceSupportKHRorvkCreateSwapchainKHRon the surviving instance calls a null pointer inside the driver. Destroying only the old device is fine, and so is the same sequence on X11.gpui_linux/src/linux/wayland/window.rs:2296a frame that finds the device lost, or is spent recovering, presents nothing and relies on the next frame callback. A compositor sends frame callbacks only for a mapped surface. When that frame was the one that maps the window (a new window, or one shown again after being hidden), no callback ever came: the window stayed invisible and every later show ended inCould not restore retained window visibility.Fix
apps/desktop-gpui/patches/zed-device-lost.patch, applied to the pinned gpui:recoverkeeps the lost context in place until its replacement exists and creates the replacement on the same instance, so no instance is destroyed while another is in use. A failed attempt retries with that instance.unmapped_frame_needs_retry, with unit tests).GPUI_INJECT_DEVICE_LOSS=<file>is a test hook: creating the file makes the renderer's next frame end as it does when the driver reports the device lost.scripts/linux-desktop-harness/scenario-device-loss.shuses it in the Hyprland job: close the main window, lose the device, launch Cap again, and the window must come back.Before and after
Tesla T4, NVIDIA 595.112.07 (open kernel module), Wayland, camera preview running. The device loss is injected by a test-only wgpu-hal build that returns a lost device from queue submit. Everything after that, including the segfault, is the real driver. Two runs of each, same outcome both times.
painted_fps=0.0, later shows failThe hidden-window row reproduces the log sequence in the issue:
camera preview resumed,wgpu device lost: reason=Unknown,GPU device lost, recreating context..., thenpainted_fps=0.0.Hyprland 0.57 on software rendering,
SCENARIO=device-loss, three runs of each:shown_againrecoveredrestore_failedLimits


Confidence Score: 5/5
The PR appears safe to merge; no actionable issue was established.Summary
This PR changes Linux GPU recovery and adds a hidden-window regression scenario.
richiemcilroyexplicitly acknowledges that instance reuse has no CI test because reproducing the crash requires NVIDIA’s driver. That known limit is not reported as a finding.Reviews (1) · Last reviewed commit: "fix(desktop-gpui): recover from a lost G..." · Reviewed by Greptile