Commit graph

31 commits

Author SHA1 Message Date
Albab Hasan
1c16e13a2b
gpui_wgpu: Respect buffer_font_fallbacks setting (#54878)
wires user configured `FontFallbacks` into the cosmic text path. the
chain is resolved at font load time and stored on each `LoadedFont`.
`layout_line` splits each `FontRun` into spans by codepoint coverage and
emits one `Attrs` per slot so cosmic text shapes each span with the
correct face. inheriting codepoints (marks, zwj, zwnj, variation
selectors) stick to the current span so emoji zwj sequences and
combining marks are not torn across faces.

Closes #17254

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] Performance impact has been considered and is acceptable
- [x] Tests cover the new/changed behavior
- [] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)

Release Notes:

- added support for `buffer_font_fallbacks` on linux
2026-05-15 15:34:18 +00:00
Xiaobo Liu
bfe5dfb4a1
gpui_wgpu: Remove redundant match arms for backend priority (#56032)
Release Notes:

- N/A
2026-05-07 15:07:36 +00:00
b5l
923f315f26
gpui_linux: Fix Wayland flickering under CPU load by skipping redundant surface commit (#54214)
Some checks are pending
Congratsbot / check-author (push) Waiting to run
Congratsbot / congrats (push) Blocked by required conditions
deploy_nightly_docs / deploy_docs (push) Waiting to run
run_tests / orchestrate (push) Waiting to run
run_tests / check_style (push) Waiting to run
run_tests / clippy_windows (push) Blocked by required conditions
run_tests / clippy_linux (push) Blocked by required conditions
run_tests / doctests (push) Blocked by required conditions
run_tests / clippy_mac (push) Blocked by required conditions
run_tests / clippy_mac_x86_64 (push) Blocked by required conditions
run_tests / run_tests_windows (push) Blocked by required conditions
run_tests / run_tests_linux (push) Blocked by required conditions
run_tests / run_tests_mac (push) Blocked by required conditions
run_tests / check_workspace_binaries (push) Blocked by required conditions
run_tests / build_visual_tests_binary (push) Blocked by required conditions
run_tests / check_wasm (push) Blocked by required conditions
run_tests / check_dependencies (push) Blocked by required conditions
run_tests / check_docs (push) Blocked by required conditions
run_tests / check_licenses (push) Blocked by required conditions
run_tests / check_scripts (push) Blocked by required conditions
run_tests / check_postgres_and_protobuf_migrations (push) Blocked by required conditions
run_tests / extension_tests (push) Blocked by required conditions
run_tests / tests_pass (push) Blocked by required conditions
Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [ ] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Closes #32792 
Closes #38266 
Closes #54133

Release Notes:

- Fixed graphical corruption that could occur when using Wayland

----

**What**: Fixes flickering on Wayland (Sway/wlroots) under CPU load
(e.g. rust-analyzer running). The bug only reproduces in release builds
- debug builds are too slow to hit the race window.

Environment where this was reproduced: Intel GPU (both Xe KMD and i915),
Mesa 26.0.4, Sway 1.11.

**Why**: When wgpu presents a frame on Wayland+Vulkan, it calls
`vkQueuePresentKHR,` which - as required by the Vulkan spec -
synchronously issues `wl_surface.attach`, `wl_surface.damage`, and
`wl_surface.commit` to the compositor before returning. The commit also
picks up any pending frame callbacks.

Zed's `completed_frame()` independently calls `state.surface.commit()`.
This is a redundant second commit on the same surface. Under load, the
Wayland socket dispatch can be delayed enough that both commits are in
flight in close succession, and the ordering becomes timing-dependent.
When Zed's commit reaches the compositor before Mesa's attach+commit
sequence has been fully flushed, the compositor sees a commit with no
buffer attached, fires `wl_callback::Done` immediately, and Zed starts
the next frame too early - Mesa's real buffer arrives late, causing the
visible flicker.

Under no load, Mesa's synchronous commit consistently reaches the
compositor first, so the bug doesn't appear.

**Fix**: Track whether `renderer.draw()` actually called
`frame.present()`. When it did, Mesa owns the `wl_surface.commit()` for
that frame - skip Zed's commit in `completed_frame()`. Only commit
ourselves when wgpu didn't present (surface not configured, lost,
occluded, etc.) - in those cases Mesa won't commit, and we need to keep
the frame callback alive.

---------

Co-authored-by: Benjamin Laib <b5l@users.noreply.github.com>
Co-authored-by: John Tur <john-tur@outlook.com>
2026-05-06 03:40:02 +00:00
Conrad Irwin
008d54299b
Try to reduce linux wGPU crashes better (#55343)
Updates #54349

There were two problems:
* The crash never happened, instead we'd always retry.
* When re-trying it seemed like we were picking llvmpipe. Claude's
suggestion was that immediately after wake, the real GPU isn't yet
awake, and so we pick llvm. Avoid this by disallowing llvmpipe on retry

Release Notes:

- linux: Reduced crash rate when recovering GPUs
2026-05-05 02:24:23 +00:00
John Tur
e5db37f7d0
Use embedded bitmaps in fonts on Linux (#55202)
Release Notes:

- Added support for using embedded bitmaps in fonts on Linux
2026-04-29 13:23:13 +00:00
John Tur
ee3b65773e
Support BGR subpixel layout (#55174)
Release Notes:

- Added text rendering support for BGR subpixel layouts.
2026-04-29 12:26:19 +00:00
Lukas Wirth
c5a2807492
Remove smol as a dependency from a bunch of crates (#53603)
We aren't making use of it in these crates and it unblocks some
web-related work

Release Notes:

- N/A or Added/Fixed/Improved ...
2026-04-24 10:29:51 +00:00
Conrad Irwin
5102ac14ba
Try to recover even harder from linux GPU errors (#54349)
Release Notes:

- N/A
2026-04-21 09:55:14 +02:00
Lukas Wirth
a62ae579ab
Performance tweaks (#54321)
Release Notes:

- N/A or Added/Fixed/Improved ...
2026-04-21 07:25:22 +00:00
Oleksiy Syvokon
dc3b25a4f4
gpui_wgpu: Fix WGPU panic from unsupported atlas texture formats (#53808)
We were assuming that `Bgra8Unorm` always works, which was causing the
panic on configurations that don't support it ("wgpu-hal invariant was
violated: Requested feature is not available on this device")

This change makes a proper fallback to `Rgba8Unorm`. In the worst case,
if a device doesn't support that as well (highly unlikely), we return a
proper error instead of a panic.


Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Closes ZED-69S

Release Notes:

- Fixed panic on devices that don't support BGRA8
2026-04-13 18:17:55 +03:00
Kirill Bulatov
3450c48aa5
Unify dirs dependency (#53775)
Corresponding font-kit commit:
94b0f28166

Before, Zed has 3 different versions of `dirs` crate to compile, this PR
bumps the related dependencies to have one, latest, version of `dirs`
instead.

Release Notes:

- N/A
2026-04-13 13:55:29 +03:00
Oleksiy Syvokon
e4ebd3aae5
Fix crash in WgpuAtlas when viewing a screen share (#53088)
When atlas tiles are rapidly allocated and freed (e.g. watching a shared
screen in Collab), a texture can become unreferenced and be removed
while GPU uploads for it are still pending. On the next frame,
`flush_uploads` indexes into the now-empty texture slot and panics:

```
  thread 'main' panicked at crates/gpui_wgpu/src/wgpu_atlas.rs:231:40:
  texture must exist...

  #11 core::option::expect_failed
  #12 gpui_wgpu::wgpu_atlas::WgpuAtlas::before_frame
  #13 gpui_wgpu::wgpu_renderer::WgpuRenderer::draw
```

This change drains pending uploads for a texture when it becomes
unreferenced in `remove`, and skips uploads for missing textures in
`flush_uploads` as a safety net.

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable


Release Notes:

- Fixed occasional crashes when viewing a screen share
2026-04-03 22:31:03 +03:00
Oleksiy Syvokon
924ac5c99b
gpui_wgpu: Guard against device feature mismatch (#52820)
This should prevent the "wgpu-hal invariant was violated (usage error):
Requested feature is not available on this device" panic, although I'm
not 100% sure (there's a possibility that a device reports the feature
but fails to use it). At the very least, we get more logging

I've tested this fix by patching code to emulate a situation where
device features change after the creation, but that may be not
representative of the real world failure.


Addresses ZED-5G1

Release Notes:

- N/A
2026-03-31 20:08:20 +03:00
Balamurali Pandranki
ef42f9db2d
gpui_wgpu: Add surface lifecycle methods for mobile platforms (#50815)
## Summary

- Add `unconfigure_surface()` and `replace_surface()` methods to
`WgpuRenderer` for mobile platform window lifecycle management
- Prefer `PresentMode::Mailbox` (triple-buffering) over `Fifo` to avoid
blocking during lifecycle transitions
- Early return in `draw()` when surface is unconfigured to prevent
driver hangs

## Motivation

On Android, the native window (`ANativeWindow`) is destroyed when the
app goes to the background and recreated when it returns to the
foreground. The same happens during orientation changes. Without surface
lifecycle methods, the only option is to destroy the entire
`WgpuRenderer` and create a new one on resume.

The problem: GPUI's scene cache holds `AtlasTextureId` references from
the old renderer's atlas. A new renderer has an empty atlas, so those
cached IDs cause index-out-of-bounds panics.

The fix: Keep the renderer (device, queue, atlas, pipelines) alive
across surface destruction. Only the wgpu `Surface` needs to be
replaced.

### `unconfigure_surface()`
Marks the surface as unconfigured so `draw()` skips rendering via the
existing `surface_configured` guard. Drops intermediate textures that
reference the old surface dimensions. The renderer stays fully alive.

### `replace_surface()`
Creates a new `wgpu::Surface` from fresh window handles using the
**same** `wgpu::Instance` that created the original adapter/device.
Reconfigures the surface and marks it as configured so rendering
resumes. All cached atlas textures remain valid.

### PresentMode::Mailbox
`Fifo` (VSync) blocks in `get_current_texture()` and can deadlock if the
compositor is frozen during a lifecycle transition (e.g.
`TerminateWindow` → `InitWindow` on Android). Mailbox (triple-buffering)
avoids this. Falls back to `AutoNoVsync` → `Fifo` if unsupported.

### draw() early return
Some drivers (notably Adreno) block indefinitely when acquiring a
texture from an unconfigured surface. The early return prevents this.

## Context

This is needed by
[gpui-mobile](https://github.com/itsbalamurali/gpui-mobile), a project
bringing GPUI to Android and iOS. The Android implementation needs these
methods to handle:

1. **Background/foreground transitions** — `TerminateWindow` destroys
the native window, `InitWindow` recreates it
2. **Orientation changes** — Surface is destroyed and recreated with new
dimensions
3. **Split-screen transitions** — Similar surface recreation

Without this change, we maintain a local fork of `gpui_wgpu` with just
these additions. Upstreaming them would let mobile platform
implementations use the official crate directly.

## Test plan

- [x] Tested on Android (Motorola, Adreno 720 GPU) — 3 consecutive
background/foreground cycles, zero panics, atlas textures preserved
- [x] Tested orientation changes (portrait→landscape→portrait) — surface
replacement completed in <40ms per rotation
- [x] Verified `draw()` correctly skips rendering when surface is
unconfigured
- [x] Verified no regression on desktop — methods are additive, existing
code paths unchanged
- [x] PresentMode fallback chain works on devices that don't support
Mailbox

## Release Notes

- N/A
2026-03-31 13:16:53 +00:00
Cameron Mcloughlin
0570f6f68c
wgpu: Fix surface validation error (#51935)
Release Notes:

- N/A or Added/Fixed/Improved ...

---------

Co-authored-by: John Tur <john-tur@outlook.com>
2026-03-20 06:32:49 +00:00
AxXxB
22f3d06c0e
gpui_wgpu: Release surface resources during destroy (#51561)
## Summary

Implements the fix proposed by @israelrios in
https://github.com/zed-industries/zed/issues/50269#issuecomment-4049006746.

The issue comment narrowed the hang down to X11 window teardown:

- when the Settings window is closed on X11, the UI thread can stall
while `WgpuRenderer` is dropped during final `X11WindowState` teardown
- at that point, the X11 window has already been destroyed
- the proposed fix is to make `WgpuRenderer::destroy()` release
surface-bound GPU resources eagerly so the native window is destroyed
only after the `wgpu::Surface` and related resources are gone

This PR applies that change in `crates/gpui_wgpu/src/wgpu_renderer.rs`
by calling `self.resources.take()` inside `destroy()`.

## Validation

I confirmed this fix locally on Linux Mint 21.3 Cinnamon by applying it
to the `v0.227.1` build:

- opening and closing Settings no longer causes the main window to hang

## References

- Refs #50269
- Original analysis and fix proposal by @israelrios:
https://github.com/zed-industries/zed/issues/50269#issuecomment-4049006746

Release Notes:

- Fixed a Linux/X11 issue where closing the Settings window could cause
Zed to hang.
2026-03-19 08:24:40 +00:00
John Tur
a7c9c24f40
Update to wgpu v29 (#51889)
This release includes the OpenGL fixes which were sent upstream.

Release Notes:

- N/A
2026-03-19 07:57:57 +01:00
Conrad Irwin
9acb32fd1f
Linux: Handle device lost with wgpu (#50898)
Release Notes:

- Linux: Handle GPU device loss gracefully
2026-03-05 22:59:48 -07:00
John Tur
c1cbcb612d
Fix handling of surface.configure on Linux (#50640)
Closes #50574

Release Notes:

- Fixed Zed not being responsive on some Linux configurations

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
2026-03-03 21:47:57 +00:00
Conrad Irwin
1d443f69f6
Add error handling to keep Zed running in the face of transient wgpu errors (#50539)
Release Notes:

- linux: Reduce crashes in the face of transient GPU errors
2026-03-02 16:04:40 -07:00
Conrad Irwin
4be8544777
wGPU: Select more specifically (#50528)
This uses the compositor hints if available to pick the best GPU. If
none is
available, it tries each GPU in turn, and the first that actually works
is chosen

Release Notes:

- Linux: Select a more appropriate GPU

---------

Co-authored-by: John Tur <john-tur@outlook.com>
2026-03-02 13:30:40 -07:00
Conrad Irwin
2757aa4140
Clamp window size on wgpu (#50329)
Fixes ZED-59P

Release Notes:

- Linux: Fix panic when requested window size was larger than supported
by your GPU
2026-02-27 20:59:28 +00:00
Conrad Irwin
69d6bfd789
Avoid panicking in wgpu rendering during resize (#50169)
Fixes Zed-5AW
Fixes Zed-5AP

Claude believes this is the right fix, but would love someone who knows
more about graphics than me to take a look: @reflectronic / @zortax?

The panic is:
```
wgpu error: Validation Error

Caused by:
  In Texture::create_view
    Texture with 'path_intermediate' label is invalid
gpui::platform::wgpu::wgpu_renderer::WgpuRenderer::create_path_intermediate (wgpu_renderer.rs:742)
gpui::platform::wgpu::wgpu_renderer::WgpuRenderer::update_drawable_size (wgpu_renderer.rs:784)
gpui::platform::linux::x11:🪟:X11WindowStatePtr::set_bounds (window.rs:1169)
gpui::platform::linux::x11::client::X11Client::handle_event (client.rs:902)
```

or:
```
wgpu error: Validation Error

Caused by:
  In Texture::create_view
    Texture with 'path_intermediate' label is invalid

gpui::platform::wgpu::wgpu_renderer::WgpuRenderer::create_path_intermediate (wgpu_renderer.rs:742)
gpui::platform::wgpu::wgpu_renderer::WgpuRenderer::new (wgpu_renderer.rs:274)
gpui::platform::linux::x11:🪟:X11WindowState:🆕:{{closure}} (window.rs:698)
gpui::platform::linux::x11:🪟:X11WindowState::new (window.rs:488)
gpui::platform::linux::x11:🪟:X11Window::new (window.rs:814)
gpui::platform::linux::x11::client::X11Client::open_window (client.rs:1514)
gpui::platform::linux::platform::<T>::open_window (platform.rs:289)
gpui:🪟:Window::new (window.rs:1119)
gpui::app::App::open_window::{{closure}} (app.rs:1025)
gpui::app::App::update (app.rs:835)
gpui::app::App::open_window (app.rs:1022)
```

I haven't seen a Wayland equivalent (not sure if that's because it
doesn't happen on Wayalnd or because I havent' seen it yet)

Release Notes:

- Linux: Fixed a panic in the new WPGU renderer during resize
2026-02-27 13:53:32 -07:00
John Tur
47c5a31ac5
Dynamically detect surface size limits on WGPU (#50340)
Fallout from https://github.com/zed-industries/zed/pull/50270

Release Notes:

- N/A

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
2026-02-27 20:46:18 +00:00
Conrad Irwin
30ceb9176c
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
2026-02-27 13:24:53 -07:00
John Tur
7e582468db
Improve GPU selection on Linux (#50274)
Follow-up to https://github.com/zed-industries/zed/pull/50270

Release Notes:

- N/A
2026-02-27 07:59:06 +00:00
John Tur
f0535ddc3c
Relax device limits for WGPU (#50270)
Plus some minor cleanup.

Release Notes:

- Fixed GPU acceleration not working on certain Linux devices.
2026-02-27 01:31:20 -05:00
Lukas Wirth
14f37ed502
GPUI on the web (#50228)
Implements a basic web platform for the wasm32-unknown-unknown target
for gpui

Release Notes:

- N/A *or* Added/Fixed/Improved ...

---------

Co-authored-by: John Tur <john-tur@outlook.com>
2026-02-26 18:36:50 +01:00
Conrad Irwin
ad2b26261e
Clamp textures on Linux too (#50025)
Port of #10314 to the wgpu renderer

Closes #ISSUE

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:

- Fixed a panic when rendering an image larger than the GPU could
support.
2026-02-24 22:01:21 +00:00
Conrad Irwin
564424b31f
Defer wgpu context creation until we have a surface (#49926)
Fixes ZED-54X

Release Notes:

- Linux: wait to request a graphics context until we have a window so we
can (ideally) pick a better context or (less ideally) fail more
gracefully.

---------

Co-authored-by: Zed Zippy <234243425+zed-zippy[bot]@users.noreply.github.com>
2026-02-24 06:27:31 +00:00
Piotr Osiewicz
bc31ad4a8c
gpui: Extract gpui_platform out of gpui (#49277)
#2874 on steroids

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:

- N/A

---------

Co-authored-by: Eric Holk <eric@zed.dev>
2026-02-19 18:57:49 +01:00