Repository navigation
winit-host: flush queued writes when the frame cannot be acquired - #5
Merged
Merged
Conversation
A Timeout or Occluded surface returned before any submit, leaving every write_buffer of the frame pending in the queue. While a window stays hidden or occluded that grows without bound (about 50 MB/s in a sprite scene: one staging buffer per write). Submitting an empty batch flushes them; Outdated/Lost do the same before reconfiguring.
mtdowling
approved these changes
Oct 12, 2026
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.
Problem
Graphics::renderqueues the frame's buffer writes (instances, batches, cull uniform, …) and only then acquires the surface texture. When the acquisition returnsTimeoutorOccludedit returnsOk(false)without submitting, so everywrite_bufferof that frame stays pending in the queue with its own staging buffer. The same happens onOutdated/Lost.While a window stays hidden — minimised, fully covered, on another Space, or with the display asleep — this repeats every frame and memory grows without bound. In a 320×200 sprite scene it grows about 50 MB/s, in both malloc and IOAccelerator (GPU) regions, until the machine runs out of memory. A visible window is unaffected, which is why it is easy to miss.
malloc_historyon a hidden window after 25 s showed ~108,000 live allocations fromwgpu_hal::metal::Device::create_bufferand a 71 MB pending-writes vector inwgpu_core::device::queue::Queue::write_buffer, while the scene itself (entities, image uploads, Lua heap) was constant.Fix
Submit an empty batch before returning when no frame can be acquired (
Timeout,Occluded), and before reconfiguring onOutdated/Lost. The writes are flushed (they are deltas the next frame relies on, so dropping them would be wrong), nothing is drawn, and wgpu reclaims the staging buffers.Testing
cargo fmt --all -- --check,cargo clippy -p tecs-winit-host --all-targets -- -D warnings,cargo test -p tecs-winit-host(102 passed).nupp task verify: the Nupp suites pass (997 tests in 86 suites); the documentation step could not run in my environment (thelunamarkrock is missing from my from-source Nupp toolchain), so the gate stopped there — the Rust gates above were run directly.No automated test: the failing path needs a real window that the OS has occluded, which the offscreen host cannot produce.