Repository navigation
feat(gpui-linux): GPU and present-mode selection, FIFO on X11, deferred surface rebuild on resize - #178
Merged
Conversation
… surface rebuild On a hybrid X11 machine whose external monitor is driven by a second GPU (an NVIDIA output sink under reverse PRIME) a resize drag stalled the whole X server, pointer included, for two seconds on many sizes; the resize log put the time inside the surface rebuild. Measured there with MESA_VK_WSI_PRESENT_MODE: mailbox helped, immediate helped most. - X11 windows present with Immediate while a compositing manager owns _NET_WM_CM_S<n>, Mailbox otherwise, never FIFO. The renderer falls back from an unsupported preferred mode to Mailbox, then FIFO. - During a burst of sizes only the first rebuilds the surface; later ones are deferred, frames keep going to the old swapchain (Suboptimal is presented), and the surface is rebuilt once the sizes stop for 150 ms, at once on Lost/Outdated, or at once for a window with no frame clock. The burst gap is measured from the end of the previous rebuild. - GPU-canvas scissors are clamped to the render target, which can be smaller than the laid-out scene while a size is deferred. - The resize log line reports deferred sizes and surface rebuilds.
…; FIFO on X11 - gpu_selection (moon-gpui-wgpu, re-exported as gpui_platform::gpu_selection on Linux): an application may hand over an explicit adapter (by a stable id) and/or present mode before its first window. Adapter ids are the PCI address the Vulkan driver reports (pci-0000:01:00.0), with the driver appended when two drivers serve one card, <type>-<driver> for software devices. list_gpus() enumerates them without a window. - An explicit choice is never replaced: an unknown id, an adapter failing the surface test, a mode the surface lacks, or a mode MESA_VK_WSI_PRESENT_MODE would replace in a Mesa driver calls the application's on_unusable before the first window; later (a second window, recovery after device loss) it is logged and returned as an error so a running session is not ended. - X11 presents with FIFO by default again; the compositor => Immediate rule is removed. Wayland keeps mailbox. - One startup line names the GPU in use, its id, driver, backend, what chose it and the display server's GPU hint; another names the present mode and its source; known environment overrides are listed.
guyverino
force-pushed
the
fix/x11-resize-present
branch
from
November 28, 2026 08:38
2c0e5fc to
eb95b41
Compare
guyverino
marked this pull request as ready for review
November 28, 2026 08:39
kirillDevPro
added a commit
that referenced
this pull request
Nov 29, 2026
What was stale: docs/MOON_PATCH_QUEUE.md lists every patch MoonUI carries on top of the Zed extraction, with what a re-sync would bring back. Commit f5dc04a (#178) added two such patches and recorded neither, so a re-sync from upstream-clean would silently drop them. What the code does now, recorded as two entries: - Layer 1: moon-gpui-wgpu's gpu_selection module (re-exported as gpui_platform::gpu_selection on Linux/FreeBSD with wayland or x11). An application may name an adapter by stable id and/or a present mode before its first window; an explicit choice is never replaced but refused through on_unusable before the first renderer, logged and returned as an error after it. Re-sync restores the adapter loop without the explicit-id branch, the inline present-mode fallback and the resolved mode handed to recover. - Layer 2: X11 resize defers GPU surface rebuilds during a drag (x11/surface_pacing.rs, SETTLE = 150 ms): only the first size of a burst rebuilds at once, the rest are deferred until sizes stop, a Suboptimal frame is presented while a size is deferred, Lost/Outdated rebuild at the deferred size, recover builds at it, GPU-canvas scissors are clamped. Re-sync restores the unconditional update_drawable_size in set_bounds and the reconfigure on every Suboptimal frame. Verified by reading gpu_selection.rs, wgpu_context.rs, wgpu_renderer.rs, x11/window.rs, x11/client.rs, surface_pacing.rs and the re-exports at master, and the re-sync claims against origin/upstream-clean. Reviewed by Codex: it confirmed the API, gating, refusal, logging and re-sync claims and disputed two phrasings, both corrected (the entry no longer says "once per burst", and Suboptimal frames are presented only while a size is deferred). No issue opened.
kirillDevPro
added a commit
that referenced
this pull request
Nov 30, 2026
The crate README describes what each `moon-gpui-platform` feature gives per platform, but never mentioned `gpui_platform::gpu_selection`, added in #178: on Linux and FreeBSD, with `wayland` or `x11` enabled, an application can hand the renderer an adapter and present mode before its first window (`set_gpu_selection`) and enumerate the adapter ids it accepts (`list_gpus`); without a selection the renderer picks both itself. Verified against crates/moon-gpui-platform/src/gpui_platform.rs (the cfg-gated re-export), crates/moon-gpui-linux/src/gpui_linux.rs and crates/moon-gpui-wgpu/src/gpu_selection.rs. Also read and found current: crates/moon-gpui/docs/contexts.md, README.md and docs/COMPONENT_AUDIT.md. No issue opened. Reviewed by Codex.
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.
Linux X11 on a hybrid machine (AMD renders, external HDMI monitor driven by an NVIDIA output sink under reverse PRIME) stalled the whole X server for ~2 s on many resize steps; the stall sits in the swapchain rebuild. Testers found a working setup by hand (GPU and present mode via environment variables) and asked for it to be reachable without them, plus manual overrides.
Two commits:
fix(gpui-linux): stop an X11 resize from waiting …— during a burst of resize sizes only the first rebuilds the GPU surface; later ones are deferred inWgpuRenderer(Suboptimal frames are presented, Outdated/Lost rebuild at once) and the surface is rebuilt once the sizes stop for 150 ms (x11/surface_pacing.rs, measured from the end of the previous rebuild). GPU-canvas scissors are clamped to the render target. The resize log line reports deferred sizes and rebuilds.feat(gpui-linux): let the application choose the GPU and present mode; FIFO on X11— newgpu_selectionmodule (moon-gpui-wgpu, re-exported asgpui_platform::gpu_selectionon Linux):set_gpu_selection(GpuSelection { adapter, present_mode }, on_unusable)before the first window;list_gpus()without a window;env_overrides();parse_present_mode.VK_EXT_pci_bus_info(pci-0000:01:00.0), driver appended when two drivers serve one card,<type>-<driver>for software devices. Stable across enumeration order.MESA_VK_WSI_PRESENT_MODEwould replace in a Mesa driver (exact match, as Mesa'swsi_common.cdoes) →on_unusablebefore the first window; afterwards (later window, recovery after device loss) logged and returned as an error.GPU in use: <name> [<id>], driver …, backend; chosen by <reason>; display server GPU hint: …,present mode: <mode> (<source>),GPU environment overrides: ….Consumer: MoonTerminal
--list-gpus,--gpu,--present-mode(separate PR there).Checked:
cargo check/clippy ofmoon-gpui-linux,moon-gpui-platform(x11, wayland) forx86_64-unknown-linux-gnu— no warnings on changed lines;cargo test -p moon-gpui-wgpu(25 passed, incl. id and present-mode tests); the terminal built for Windows and type-checked for Linux against this branch. Real-hardware check is done by the testers on the release build.