Skip to content

fix(windows): a resize keeps the swap chain's frame-latency wait and drains surplus counts - #1545

Merged
Hona merged 1 commit into
devfrom
fix/1426-win-slot-resize
Nov 23, 2026
Merged

Hona merged 1 commit into
devfrom
fix/1426-win-slot-resize

Conversation

@Hona

@Hona Hona commented Nov 23, 2026

Copy link
Copy Markdown
Member

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) and OverlayCore::rescale (overlay/surface.rs) called slot.reset() before each configure.
  • Slot::take dropped Owed and Waiting when the configure generation or the waitable handle value changed.

A wgpu-hal DX12 configure on a live surface calls IDXGISwapChain::ResizeBuffers on 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.

sequenceDiagram
  participant R as resize step
  participant S as Slot
  participant D as DXGI semaphore
  R->>S: reset() (before)
  R->>D: ResizeBuffers (same object, count kept)
  S->>S: Free -> draw without taking a count
  Note over D: +1 surplus count per step
Loading

Change

  • An in-place configure (resize, blend switch) calls Slot::reconfigured(ok). It keeps Owed and Waiting on success and resets only when the configure fails, because wgpu then drops the swap chain.
  • Slot::take no longer compares configure generations or handle values. The Wait holds its own duplicate of the handle, so it still wakes after ResizeBuffers. A wait clears only when the surface has no waitable left. A wait on a lost object still gives up after GIVE_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.
  • When Owed finds 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.
  • PR fix(window): a resize exceeding max_texture_dimension_2d keeps the previous drawable and viewport, and initial surfaces clamp to the limit #1449's drawable-size logic in resize_surface is unchanged.

Verification

  • slot_tests.rs uses a real Win32 semaphore and a duplicate handle to model ResizeBuffers returning a new handle to the same object:
    • slot_keeps_waiting_and_owed_across_resize_reconfigure fails on the old code: Draw instead of Later.
    • slot_drains_surplus_semaphore_counts_on_owed_take.
    • slot_clears_state_on_explicit_reset_failed_reconfigure_or_lost_waitable.
  • Not measured live: nobody resized a real window, and frame timing during and after a drag was not measured. The fix rests on reading the DXGI and wgpu-hal code and on the unit tests above.
  • Windows: live resize lags about 1 s since 1dc3b333 (#1222) #1311, the resize lag of about 1 s, comes from the same reset. Someone must check it on hardware before closing it.

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.

Windows: after a live resize, hover and scroll lag and frames come "in waves" (swap-chain slot reset on every resize, since 1dc3b333)

1 participant