Skip to content

Keep dropped images in the atlas until the next draw - #19

Open
katulevskiy wants to merge 4 commits into
zeronsh:zeron/drag-needs-held-buttonfrom
katulevskiy:fix/atlas-drop-while-presented
Open

katulevskiy wants to merge 4 commits into
zeronsh:zeron/drag-needs-held-buttonfrom
katulevskiy:fix/atlas-drop-while-presented

Conversation

@katulevskiy

@katulevskiy katulevskiy commented Nov 8, 2026 •

Copy link
Copy Markdown

Stacked on #18: review only the last commit, 15ee708.

A Linux user's window aborted on Zeron 0.2.138 (zui b564a34):

panicked at crates/gpui_wgpu/src/wgpu_atlas.rs:146:36: texture must exist
panicked at wgpu-hal-29.0.4/src/vulkan/swapchain/native.rs:359:58: Trying to destroy a SwapchainAcquireSemaphore that is still in use by a SurfaceTexture
panic in a destructor during cleanup

Cause. Window::drop_image freed the image's tiles right away. When they were the last tiles in their atlas texture, the texture was freed too. A window can present its last frame again without redrawing it: during high-rate input, with require_presentation, or on a forced present on Wayland. That frame still names the freed texture, so get_texture_info panicked. A second panic in the swapchain's destructor during the unwind then aborted the process.

Fix.

  • Window::drop_image queues the image's atlas keys. The next draw() removes them before painting, once the frame that might sample them is being replaced. This change is platform independent.
  • WgpuAtlas::get_texture_info returns Option. When a scene still names a freed texture (a cached view replaying a dropped image, or a cleared atlas), the renderer skips that batch and sets needs_redraw. Wayland and X11 then run a forced render that bypasses cached views. This replaces the panic.

Tests.

  • window::tests::dropped_image_stays_in_the_atlas_until_the_next_draw fails before the fix and passes after it.
  • wgpu_atlas::tests::texture_info_of_a_freed_texture_is_none was run on an Intel Arc (Vulkan) device.
  • cargo test -p gpui --lib: 230 passed. cargo test -p gpui_wgpu --lib: 34 passed, 2 ignored.

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Alexandre Vargas Lopez and others added 4 commits October 25, 2026 12:53
A producer that tracks damage, like an embedded browser, uploads only what
changed into an image it already painted instead of a whole new image per
frame: `Window::update_image` overwrites a region of the image's tile, and
`RenderImage::blank` with `Window::insert_blank_image` gives a frame-sized
tile without uploading blank pixels.

On Linux, a dma-buf another process renders into is imported into the
Vulkan device once (`Window::import_dmabuf`) and its damaged regions are
copied on the GPU, so frames never touch the CPU. The device opens with
VK_EXT_image_drm_format_modifier when the GPU has it, so tiled layouts
import too: GPUs whose EGL renders only to tiled layouts (NVIDIA) share
frames as well. `Window::dmabuf_target` names the render node and the
layouts the atlas imports: uncompressed ones only, since wgpu moves an
imported image out of an undefined layout without acquiring it from the
producer's queue, which may reinitialize compression metadata.

`on_complete` runs exactly once, outside the atlas lock, after the GPU has
finished all work queued before it, errors included, so a producer can
recycle a buffer as soon as the GPU stops reading it. Pixel uploads land
before the frame's copies and drop the copies they cover. A lost device
runs the pending completions and drops the imports; producers import
again.
An inactive window slows its frame callbacks to ~30 fps to save energy.
Content that follows the display, such as video or a web page, asks for
the next frame with `Window::on_next_display_frame` instead: the window
keeps the display's rate for that callback, and slows down again once
such requests stop.
A frame callback requests the next one, which only a commit sends. A draw
forced outside the frame loop left `renderer_presented` set, so the next
frame that drew nothing skipped that commit: the compositor never
answered and frames stopped. Reset it with each frame callback.
A window can present its last frame again without redrawing it (a present
from high-rate input, a forced present on Wayland). `Window::drop_image`
freed the image's tiles at once, and when they were the last ones in their
atlas texture the texture went too: re-presenting the old scene then hit
"texture must exist" in `WgpuAtlas::get_texture_info` and aborted the
process, since the swapchain's destructor panicked during the unwind.

Dropped tiles now stay until the next draw replaces the frame that may
sample them. The wgpu renderer no longer panics when a scene still names a
freed texture (a cached view replaying a dropped image, a cleared atlas): it
skips the batch and asks for a full redraw.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants