Repository navigation
fix(windows): a resize keeps the swap chain's frame-latency wait and drains surplus counts - #1545
Merged
Merged
Conversation
…drains surplus counts
This was referenced Nov 23, 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.
Fixes #1426
Refs #1311
Root cause
On Windows a frame waits for the swap chain's frame-latency semaphore (
window/win32/slot.rs). Two changes in 1dc3b33 dropped that wait on every resize:Win::resize_surface(window/surface/win.rs) andOverlayCore::rescale(overlay/surface.rs) calledslot.reset()before eachconfigure.Slot::takedroppedOwedandWaitingwhen the configure generation or the waitable handle value changed.A wgpu-hal DX12
configureon a live surface callsIDXGISwapChain::ResizeBufferson the same swap chain (vendor/wgpu-hal/src/dx12/mod.rs,Surface::configure). The swap chain's waitable semaphore and its count survive. wgpu closes its old handle and gets a new handle to the same object, so the handle value changes but the object does not.Each resize step therefore drew one frame without taking a count. That frame left one extra count in the semaphore. A live drag leaves dozens. After that,
WaitForSingleObject(object, 0)always succeeds, frames stop waiting for the compositor and queue behind DWM. The result is waves during the drag and lagging hover and scroll after it, until the app restarts.Change
Slot::reconfigured(ok). It keepsOwedandWaitingon success and resets only when the configure fails, because wgpu then drops the swap chain.Slot::takeno longer compares configure generations or handle values. TheWaitholds its own duplicate of the handle, so it still wakes afterResizeBuffers. A wait clears only when the surface has no waitable left. A wait on a lost object still gives up afterGIVE_UP_MS.reset()stays where a swap chain is replaced or dropped: reattach,rebind_alpha, hand-over, fail-over to the CPU renderer, and overlay release.Owedfinds the object signalled, it takes up to 64 extra counts. These are counts left by a reset or a timed-out wait. Without this, later frames would skip the wait.resize_surfaceis unchanged.Verification
slot_tests.rsuses a real Win32 semaphore and a duplicate handle to modelResizeBuffersreturning a new handle to the same object:slot_keeps_waiting_and_owed_across_resize_reconfigurefails on the old code:Drawinstead ofLater.slot_drains_surplus_semaphore_counts_on_owed_take.slot_clears_state_on_explicit_reset_failed_reconfigure_or_lost_waitable.