Skip to content

Windows: live resize lags and stretches on every edge #47

Done

Description

@zAcherttp

Consolidates #101 (left and top edges). Measured on current dev (5521783).

What happens

  • Right or bottom edge: while dragging, the content trails the edge. Windows stretches the old frame or shows an empty strip until the next frame lands.
  • Left or top edge: the whole page jumps sideways (or up) by the drag distance on each step, then snaps back. The gap opens at the opposite edge, the one not being dragged.

Machine: Windows 11, Intel UHD 730 + RTX 4070, 239 Hz monitor on the RTX, kit-gallery in release.

kit-gallery drag, right edge Resize steps/s surface.configure
dev before the display-GPU pick (Intel iGPU) 19 34 ms
current dev (RTX, ae0c949) 73–84 median 2.5–2.8 ms, worst 3.5–4.4 ms

Each step is now cheap, so what's left is when frames are drawn and where Windows places them.

Cause

  1. Deferred redraw. Inside Windows' size-move loop, winit reports Resized but the redraw waits for the loop's next message, so Windows shows each new size before Rune has drawn it.
  2. Origin moves on left/top drags. Until the app presents a frame at the new size, DWM shows the last frame pinned to the client area's new top-left, so the old frame moves with the edge. Drawing sooner shortens this but can't remove it.
  3. Rune can't offset the frame, because wgpu owns the composition tree. With Dx12SwapchainKind::DxgiFromVisual, wgpu-hal creates its own IDCompositionDevice, target and root visual for the HWND (wgpu-hal 30, dx12/dcomp.rs, InnerState::init) and never exposes them.

Requested change

Right and bottom edges (working reference: zAcherttp/rune windows-live-resize, where steps ran at 3.4–6 ms with no visible lag or stretch):

  1. Extend the size-move subclass (platform/win32/dpi_drag.rs already watches WM_ENTERSIZEMOVE / WM_EXITSIZEMOVE): inside the loop, draw in Resized before returning, at frame latency 1 with Immediate presents.
  2. On DX12, keep one monitor-sized swapchain for the drag and draw into a viewport of it, so steps don't reconfigure. DirectComposition windows can drop the GDI redirection bitmap (WS_EX_NOREDIRECTIONBITMAP).
  3. Clear a root with no fill to the first opaque element covering the window, so a fast drag's uncovered strip matches the page instead of black.

Left and top edges (researched, not prototyped):

  1. Rune owns the tree: create the IDCompositionDevice, a target for the HWND, a root visual and a content visual, and make the surface with wgpu::SurfaceTargetUnsafe::CompositionVisual(content) (wgpu 30, DX12). This step only moves ownership; behaviour, screenshots and transparency stay identical.
  2. In the subclass, read WM_SIZING's edge (WMSZ_LEFT, WMSZ_TOP and the corners). For each step, offset the content visual by the origin's movement since the last presented frame (SetOffsetX(+dx), SetOffsetY(+dy)) and Commit() before returning, so the old frame stays where it was on screen. When the frame at the new size presents, reset the offsets to 0 and Commit().

Risk to check before step 5: the window move (applied by DWM) and the visual offset (a DirectComposition commit) must land in the same composed frame; one frame apart, the page wobbles instead of jumping. Test with a window that moves its origin and offsets a solid-colour visual in the same step, watched at 240 Hz or captured with PresentMon. If the commit lands late, try IDCompositionDevice::WaitForCommitCompletion, or committing from WM_WINDOWPOSCHANGING before the move is applied.

Scope

  • DX12 only. Vulkan keeps the HWND swapchain and today's behaviour.
  • The owned tree is also what Mica/Acrylic backdrops and native video visuals need; research/11-platform-shells.md plans the same IDCompositionDevice / target / visual tree for the Windows shell.
  • Maximise, Snap and DPI changes can keep the deferred path.

Acceptance

  • Dragging any edge or corner at full speed, the page doesn't trail the edge or move on screen; only the uncovered strip at the dragged edge shows, in the page colour.
  • Step time stays at or under current dev (median ~2.6 ms configure) with no added frame of lag.
  • Transparent windows, overlays and screenshots are unchanged.

I can test any change on this machine (RTX 4070, plus the Intel iGPU via WGPU_ADAPTER_NAME=intel).

Activity

  1. zAcherttp commented on Nov 6, 2026

    @zAcherttp
    Author

    Update against current dev (5521783), same machine. #46 is closed, so this issue is now the request.

    GPU choice is done: dev picks the RTX ("the GPU driving the primary display", ae0c949), on DX12. That removed most of the cost in the table above:

    kit-gallery drag, right edge Resize steps/s surface.configure
    old dev (Intel iGPU) 19 34 ms
    current dev (RTX) 73–84 median 2.5–2.8 ms, worst 3.5–4.4 ms

    Still broken: the content still lags behind the edge during the drag, and Windows stretches the old frame or shows an empty strip. Each step is now cheap; it just isn't drawn before Windows shows the new size, because winit defers the redraw until the size-move loop's next message.

    Requested change (items 2 and 3 above, unchanged; windows-live-resize is a working reference):

    1. Subclass the window for WM_ENTERSIZEMOVE / WM_EXITSIZEMOVE; inside the loop, draw in Resized before returning, at frame latency 1 with Immediate presents.
    2. On DX12, keep one monitor-sized swapchain for the drag and draw into a viewport of it, so steps don't reconfigure.
    3. Clear a root with no fill to the page colour, so a fast drag's uncovered strip matches the page instead of black.
    4. Optional, separate: Rune owning its DirectComposition visual (SurfaceTargetUnsafe::CompositionVisual), for left-edge drags.

    On the branch, steps ran at 3.4–6 ms with no visible lag or stretch. I can test any change on this machine.

  2. changed the title [-]Windows: smooth live resize, and owning DirectComposition ahead of the Windows shell[/-] [+]Windows: live resize lags and stretches on every edge[/+] on Nov 6, 2026
  3. Hona commented on Nov 23, 2026

    @Hona
    Member

    The deferred-redraw and DXGI pacing causes behind this report (55217838) are fixed on current dev. Two parts of the request are not on dev: reusing a display-sized swap chain across resize steps (#1065 was closed pending fresh measurements on the new surface code) and offsetting the DirectComposition visual on left/top-edge drags. We have not measured live Windows 11 DWM resize timing on current dev.

    Pull requests that addressed this:

    If resize still lags, stretches, or jumps on current dev, please reopen with a repro:

    1. Run cargo run --release -p kit-gallery (or cargo run --release -p settings --features frame-profile with RUNE_GPU_LOG=1 and RUNE_FRAME_LOG=resize.jsonl).
    2. Drag right/bottom and left/top edges briskly (optionally test RUNE_CPU_FIRST=0 or WGPU_ADAPTER_NAME=intel).
    3. Share the commit SHA, what still trails or jumps, and a short clip or resize.jsonl.

    Thanks for the detailed measurements and reference branch.

  4. Hona commented on Nov 24, 2026

    @Hona
    Member

    Follow-up from a live check on Windows 11: we ran dev at ac452a9c2 in a live window on a 3440×1440, 165 Hz display (scale 1.0) using an NVIDIA GeForce RTX 5070 Ti on DirectX 12.

    Captures taken mid-drag during slow edge and corner drags (at intermediate sizes 584×400 on the right edge, 480×503 on the bottom edge, and 583×494 on the corner) showed the content, border, and edge bars staying flush with the frame, with no stretched or stale band.

    This only covers one machine, one display, and a DirectX 12 discrete GPU (and slow right, bottom, and corner drags). If resize still lags or stretches on your machine, please reopen with a capture.

  5. zAcherttp commented on Nov 25, 2026

    @zAcherttp
    Author

    A follow-up on the remaining live resize wobble on Windows.

    The jump on left and top drags comes from DWM showing the window's new size and the swap chain's
    frame in different compositions, and no public Windows API ties the two together. I prototyped a
    fix that applies only during a drag: frames go through a path DWM waits for at each size step, and
    on Windows 11 through the resize synchronization Windows' own UI frameworks use. With it, fast
    left-edge drags show no visible flicker or wobble.

    Findings, measurements and a proposed design are in #2113. I have a working implementation
    and can share it if the approach is wanted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions