ZIm/crates/gpui/src
Max Brunsfeld 4d00d07df1
Render paths to a single fixed-size MSAA texture (#34992)
This is another attempt to solve the same problem as
https://github.com/zed-industries/zed/pull/29718, while avoiding the
regression on Intel GPUs.

###  Background

Currently, on main, all paths are first rendered to an intermediate
"atlas" texture, similar to what we use for rendering glyphs, but with
multi-sample antialiasing enabled. They are then drawn into our actual
frame buffer in a separate pass, via the "path sprite" shaders.

Notably, the intermediate texture acts as an "atlas" - the paths are
laid out in a non-overlapping way, so that each path could be copied to
an arbitrary position in the final scene. This non-overlapping approach
makes a lot sense for Glyphs (which are frequently re-used in multiple
places within a frame, and even across frames), but paths do not have
these properties.
* we clear the atlas every frame
* we rasterize each path separately. there is no deduping.

The problem with our current approach is that the path atlas textures
can end up using lots of VRAM if the scene contains many paths. This is
more of a problem in other apps that use GPUI than it is in Zed, but I
do think it's an issue for Zed as well. On Windows, I have hit some
crashes related to GPU memory.

In https://github.com/zed-industries/zed/pull/29718, @sunli829
simplified path rendering to just draw directly to the frame buffer, and
enabled msaa for the whole frame buffer. But apparently this doesn't
work well on Intel GPUs because MSAA is slow on those GPUs. So we
reverted that PR.

### Solution

With this PR, we rasterize paths to an intermediate texture with MSAA.
But rather than treating this intermediate texture like an *atlas*
(growing it in order to allocate non-overlapping rectangles for every
path), we simply use a single fixed-size, color texture that is the same
size as thew viewport. In this texture, we rasterize the paths in their
final screen position, allowing them to overlap. Then we simply blit
them from the resolved texture to the frame buffer.

### To do

* [x] Implement for Metal
* [x] Implement for Blade
* [x] Fix content masking for paths
* [x] Fix rendering of partially transparent paths
* [x] Verify that this performs well on Intel GPUs (help @notpeter 🙏 )
* [ ] Profile and optimize

Release Notes:

- N/A

---------

Co-authored-by: Junkui Zhang <364772080@qq.com>
2025-07-25 14:39:24 -07:00
..
app Add an editor: diff clipboard with selection action (#33283) 2025-07-23 02:39:32 +00:00
elements gpui: Add scroll_to_item_with_offset to UniformListScrollState (#35064) 2025-07-25 05:13:09 +05:30
keymap Update keymap context binding behavior of > and ! (#34664) 2025-07-18 09:25:18 -06:00
platform Render paths to a single fixed-size MSAA texture (#34992) 2025-07-25 14:39:24 -07:00
text_system Improve terminal rendering performance (#33345) 2025-07-08 09:05:01 -06:00
window gpui: Improve window.prompt to support ESC with non-English cancel text on macOS (#29538) 2025-05-30 15:26:27 +00:00
action.rs gpui: Reduce manual shifting & other minor improvements (#34407) 2025-07-15 16:39:33 +02:00
app.rs collab: Add screen selector (#31506) 2025-07-21 13:44:51 +02:00
arena.rs chore: Bump Rust version to 1.88 (#33439) 2025-06-26 20:54:19 +02:00
asset_cache.rs gpui: Relax AssetLogger trait bounds (#29450) 2025-04-29 12:43:54 -07:00
assets.rs chore: Bump Rust edition to 2024 (#27800) 2025-03-31 20:55:27 +02:00
bounds_tree.rs gpui: Optimize the ordering update in the BoundsTree (#31025) 2025-05-30 08:23:27 -07:00
color.rs gpui: Reduce manual shifting & other minor improvements (#34407) 2025-07-15 16:39:33 +02:00
colors.rs gpui: Add a standard text example (#30747) 2025-05-16 17:35:44 +02:00
element.rs gpui: Add use state APIs (#34741) 2025-07-19 01:27:54 +00:00
executor.rs Add a test for remote tool use by the agent (#30289) 2025-05-08 16:53:04 -04:00
geometry.rs Migrate to schemars version 1.0 (#33635) 2025-06-30 21:07:28 +00:00
global.rs Eliminate GPUI View, ViewContext, and WindowContext types (#22632) 2025-01-26 03:02:45 +00:00
gpui.rs gpui: Add tab focus support (#33008) 2025-07-20 16:38:54 -07:00
input.rs Implement character index for point (#23989) 2025-02-04 20:15:43 +00:00
inspector.rs Add a live Rust style editor to inspector to edit a sequence of no-argument style modifiers (#31443) 2025-05-26 17:43:57 +00:00
interactive.rs gpui: Simplify Action macros + support doc comments in actions! (#33263) 2025-06-24 04:34:51 +00:00
key_dispatch.rs gpui: Simplify bindings_for_action API (#34857) 2025-07-22 10:59:51 -04:00
keymap.rs gpui: Simplify bindings_for_action API (#34857) 2025-07-22 10:59:51 -04:00
path_builder.rs Revert "gpui: Improve path rendering & global multisample anti-aliasing" (#34722) 2025-07-18 16:03:08 +00:00
platform.rs Render paths to a single fixed-size MSAA texture (#34992) 2025-07-25 14:39:24 -07:00
prelude.rs Sketch in a table for the keybindings UI (#32436) 2025-06-30 19:25:11 -04:00
scene.rs Render paths to a single fixed-size MSAA texture (#34992) 2025-07-25 14:39:24 -07:00
shared_string.rs Migrate to schemars version 1.0 (#33635) 2025-06-30 21:07:28 +00:00
shared_uri.rs Rework loading images from files (#7088) 2024-01-30 11:26:02 -05:00
style.rs Add a live Rust style editor to inspector to edit a sequence of no-argument style modifiers (#31443) 2025-05-26 17:43:57 +00:00
styled.rs Add a live Rust style editor to inspector to edit a sequence of no-argument style modifiers (#31443) 2025-05-26 17:43:57 +00:00
subscription.rs gpui: Replace Mutex with RefCell for SubscriberSet (#30907) 2025-05-19 11:08:04 +02:00
svg_renderer.rs gpui: Use static keyword with LazyLock when loading system fonts (#34555) 2025-07-18 12:35:38 +02:00
tab_stop.rs gpui: Add tab focus support (#33008) 2025-07-20 16:38:54 -07:00
taffy.rs Re-land taffy 0.8.3 (#34939) 2025-07-24 00:33:43 +02:00
test.rs Add seed argument to #[gpui::test] attribute macro (#26764) 2025-03-14 13:40:02 -03:00
text_system.rs Improve terminal rendering performance (#33345) 2025-07-08 09:05:01 -06:00
util.rs chore: Bump Rust version to 1.88 (#33439) 2025-06-26 20:54:19 +02:00
view.rs Add initial element inspector for Zed development (#31315) 2025-05-23 23:08:59 +00:00
window.rs gpui: Add tab focus support (#33008) 2025-07-20 16:38:54 -07:00