Skip to content

Windows: steady live resize by syncing each drag frame with the window's size step #2113

Backlog

Description

@zAcherttp

Follow-up to #47.

Summary

During a live resize on Windows, Rune's page wobbles: on a fast drag, content anchored to the edge
that stays still jumps by a step and comes back, most visibly on left and top drags. The cause is
that a DirectComposition swap chain's frame and the window's new size reach the screen in different
compositions, and no public Windows API ties them together.

I prototyped and measured a fix. During a drag only, each frame is drawn off-screen into a texture
shared between D3D12 and D3D11, and reaches the window in step with the resize, either through a
copy-model D3D11 swap chain or, where available, through the resize synchronization Windows' own UI
frameworks use. With the second, fast left-edge drags show no visible flicker or wobble. Outside a
drag nothing changes.

I have a working implementation (about 1,200 lines, Windows only) and can share it as a patch or a
branch if the approach is wanted. This issue records the findings and a proposed design.

Environment: Windows 11, RTX 4070, wgpu DX12, 239 Hz display, the settings example.

Root cause

While the user drags a window edge, Windows applies each new size in its size-move loop
(WM_WINDOWPOSCHANGING, WM_NCCALCSIZE, WM_SIZE, WM_PAINT) and DWM shows it at its next
composition. A frame presented through the window's DirectComposition flip-model swap chain lands on
its own schedule, often one composition before or after the new size. When the size change also
moves the window's corner (left and top edges), a frame shown at the wrong size is shown at the
wrong position.

Electron reached the same conclusion in 2025 ("Windows provides no way for us to synchronize those
operations"), and Firefox (bugs 1617517, 1494522) and Chromium show the same artifacts.

What was measured

  • Every composed frame captured at 240 fps with Desktop Duplication, scored per frame: whether a
    control anchored to the still edge stays at the same screen position.
  • A per-step timer from Windows announcing a size (WM_WINDOWPOSCHANGING) to the paint that shows
    it.
  • Sizes applied per second during scripted drags.
  • Hand tests on the panel itself, since some artifacts never appear in a capture (see below).

Approaches that didn't work

Approach Result
A drawable larger than the window during the drag, Immediate presents Halved step-to-frame latency; the frame still isn't synced with the size
Offsetting the DirectComposition root by each step's corner move Worse on fast drags: the offset lands a refresh before the move (still edge steady on 12% of moving frames, against 55–61% on dev)
Drawing the new size in WM_WINDOWPOSCHANGING The frame lands a refresh early instead of late (22% steady)
Waiting for a composition (DwmFlush) before each step Halves the step rate and doubles the error

What works

Drawing through the window's redirection surface. DWM waits for a redirected window to paint
at its new size before showing it. Rune's CPU renderer already works this way, and holds the still
edge at 0 px on every captured frame of fast drags. A GPU frame copied back and drawn with BitBlt
in WM_PAINT does too (100% of moving frames steady, against 55–61% on dev). This is also the
approach Raph Levien recommends and Flutter's Windows embedder takes.

DWM only waits about one refresh, though. With a CPU readback, a step took a median 4.5–4.9 ms and
69–85% of steps ran past a 239 Hz refresh; a late step is shown unsynced, which on a left drag looks
like an occasional one-refresh jump.

Keeping the copy on the GPU. D3D12 only creates flip-model swap chains, which bypass the
redirection surface. During a drag, the D3D12 frame is drawn into a texture shared with a D3D11
device on the same adapter (a shared fence orders the two on the GPU), and a D3D11 copy-model swap
chain (DXGI_SWAP_EFFECT_DISCARD) presents it into the redirection surface. No readback and no CPU
wait. Fewer steps run late, but a fast left drag still flickers occasionally.

Windows' resize synchronization. UWP and WinUI keep content in step with a resize through a
handshake that isn't in the public API: user32 ordinals 2615 (EnableResizeLayoutSynchronization)
and 2614 (GetResizeDCompositionSynchronizationObject), the step's layout reported done through
ordinal 2538, and IDCompositionDesktopDevicePartner6::SynchronizedCommit (Windows 11 22H2 and
later). Magpie and EpicGames/raddebugger#1033 use it on plain Win32 windows. With it, each step's
frame is copied from the same shared texture into a DirectComposition surface on a topmost layer and
committed with that step's synchronization object, and DWM holds the step until the commit arrives.
On fast left-edge drags there's no visible flicker.

Results

Scripted A/B, two alternating rounds per path, dragging each edge out and back at a 0.3 s and a
0.08 s pace:

Path Step median Steps past a refresh Sizes/s (left, right) Fast left drag, by eye
dev (DirectComposition swap chain) — — — wobbles
GPU frame read back, GDI paint 4.5–4.9 ms 69–85% — steady, occasional jump
D3D11 copy-model swap chain 3.1–3.8 ms about 6% 238–247 steady, occasional flicker
Resize synchronization 2.3–2.7 ms 0.2% 149–237 steady, no visible flicker

With resize synchronization, Windows applies fewer sizes per second on horizontal drags, because it
holds each step until its frame is committed. The edge follows the cursor in slightly larger
increments, but every step shown is complete.

Pitfalls worth knowing

  • The copy must happen inside the WM_PAINT Windows sends for the step (BeginPaint/EndPaint);
    drawing in WM_SIZE is slower and isn't waited for.
  • Windows keeps the old client pixels aligned to the client area's top-left corner, so a left or top
    drag can briefly show them shifted by the step. Returning WVR_VALIDRECTS from WM_NCCALCSIZE
    with rectangles that keep them in place on screen (or SWP_NOCOPYBITS) fixes it.
  • Any WM_ERASEBKGND between steps is composed as a flash, so erasing is suppressed during a drag.
  • Presenting to the hidden D3D12 swap chain during a drag still reaches a hardware overlay plane
    and flickers on the panel. Captures never show this, because capturing makes DWM compose every
    plane; it has to be checked by eye. Drag frames are therefore drawn off-screen with no present.
  • After the drag, one frame is presented through the normal swap chain, and Rune's composition tree
    is restored only once the GPU has finished it.

Proposed design

  1. Only between WM_ENTERSIZEMOVE and WM_EXITSIZEMOVE: take Rune's DirectComposition tree off
    and draw each frame off-screen into a D3D12 texture shared with D3D11.
  2. Where resize synchronization is available, commit each frame with its step's synchronization
    object. Every step's object is either used or released as soon as Windows has handled the step,
    so the window can never wait for a timeout.
  3. Otherwise fall back to the D3D11 copy-model swap chain, and failing that to a CPU readback drawn
    in WM_PAINT.
  4. After the drag, present through the normal swap chain and restore the tree.

The drag's phases (idle, starting, drawing, leaving) are one explicit state machine, and nothing
changes for translucent windows or windows without a Rune-owned composition tree.

Open question

Resize synchronization is undocumented: its interface layout differs between Windows builds, and a
missed completion would stall the window. Should it be on by default on Windows 11 22H2 and later,
behind a build check with the D3D11 swap chain as the fallback, or opt-in behind a flag?

References

Activity

  1. opencodejr commented on Nov 25, 2026

    @opencodejr
    Contributor

    Thanks for the thorough write-up and the A/B numbers. This is a clear follow-up to the left/top-edge part of #47 that never landed (offsetting the DirectComposition visual), so I'm tracking it as a feature request.

    Where current dev stands, for anyone picking this up:

    • crates/rune/src/platform/win32/dpi_drag.rs only tracks whether a window is inside WM_ENTERSIZEMOVE..WM_EXITSIZEMOVE. It's the natural home for the drag phases, which AGENTS.md wants as one explicit enum State plus step function (rune::machine), as your design already does.
    • crates/rune/src/platform/win32/frame.rs already handles WM_NCCALCSIZE for the custom frame, so the WVR_VALIDRECTS change needs to fit alongside that.
    • crates/rune/src/platform/win32/dcomp_handover.rs owns the DirectComposition tree (Windows: a window's first frame is drawn on the CPU and shown before its GPU exists; the GPU takes over when it's ready #689), which the drag path would take off and restore.
    • There's no D3D11 or SynchronizedCommit code in the repo yet.

    On your open question: whether the undocumented resize synchronization is on by default (behind a Windows build check, with the D3D11 copy-model swap chain as the fallback) or opt-in is a call for the maintainers. Keeping the fallback chain as you describe it would make either choice workable.

    If you share the branch, it will be easier to review in pieces. The repo keeps Rust files under about 800 lines, and changes that affect app output need a changelog/unreleased/ entry.

  2. opencodejr commented on Nov 25, 2026

    @opencodejr
    Contributor

    I haven't opened a pull request for this. The change needs Windows-only interop with undocumented APIs (user32 ordinals 2614/2615/2538, IDCompositionDesktopDevicePartner6::SynchronizedCommit), and the only real check is by eye on a Windows 11 machine, because captures hide the overlay-plane flicker. I can't build or run that here, and your measured implementation is a better starting point than a rewrite I couldn't verify.

    If you'd like to share your branch, review would go easier if it came in pieces:

    1. The drag state machine in crates/rune/src/platform/win32/dpi_drag.rs (one enum State plus step, per AGENTS.md) with the shared D3D12/D3D11 texture and the copy-model swap chain fallback.
    2. The WVR_VALIDRECTS and erase-suppression handling, which sits beside the existing WM_NCCALCSIZE code in crates/rune/src/platform/win32/frame.rs.
    3. Resize synchronization behind its build check or flag, depending on what the maintainers decide on your open question.

    The repo keeps Rust files under about 800 non-test lines and asks for a changelog/unreleased/ entry for changes that affect app output.

  3. Hona commented on Nov 25, 2026

    @Hona
    Member

    Thanks for the detailed measurements and analysis.

    We have decided to build the first path in-house using public Microsoft-documented APIs only, off by default at first. We will not build the second path because it relies on private, undocumented Windows interfaces, and we will not offset the DirectComposition visual.

    One correction to the earlier comments here: as README.md notes, Rune does not take outside code or pull requests, so you do not need to share a branch. Your eyes on real hardware would be very helpful, though — we cannot watch a live drag on a Windows display right now, so once the opt-in lands on dev we will follow up here with how to turn it on and ask you to try it on your machine.

  4. Hona commented on Nov 25, 2026

    @Hona
    Member

    The opt-in drag-only resize path has landed on dev in #2133 (14e80f90d), built in-house with public Microsoft-documented APIs only, and off by default. As noted earlier, we are not building the undocumented synchronization path and Rune does not take outside code (README.md).

    How to try it

    No rebuild of Rune is needed — set RUNE_RESIZE_SYNC=1 in the environment when launching an example or app, for example in PowerShell:

    $env:RUNE_RESIZE_SYNC = "1"
    cargo run --release -p settings
    cargo run --release -p kit-gallery

    When RUNE_RESIZE_SYNC is unset or 0, Windows apps stay on the normal DirectComposition flip-model path with zero D3D11 devices, shared textures, or second swap chains created. Transparent windows, overlays, WGPU_DX12_PRESENTATION_SYSTEM=hwnd, and CPU-first/handover/rebinding windows always keep the normal path.

    What to test

    • Fast left-edge and top-edge drags (growing and shrinking) on examples/settings and examples/kit-gallery, checking for wobble, entry/exit flash, and any flicker or MPO overlay artefacts.
    • The same drags with a playing video on screen and with an overlay open.
    • Cancelling a drag with Escape, dragging only the title bar (move without resize), and rapid repeated drags.

    What has and has not been checked

    • Checked off screen: the drag state machine (Idle / Entering / Dragging / Leaving) and its exclusions and abort exits, WVR_VALIDRECTS rect math, zero drag GPU allocations when RUNE_RESIZE_SYNC is off, and real-adapter D3D12-to-D3D11 shared-texture and shared-fence transfer with bit-exact pixel parity and zero leaked textures on exit.
    • Not checked in a live window: nobody has seen this path run in a live window on a Windows 11 display yet.

    Please report what you see here (with a capture if you can) — whether this becomes the default will be decided after a live Windows 11 check.

  5. zAcherttp commented on Nov 25, 2026

    @zAcherttp
    Author

    Thanks for building it. I tried RUNE_RESIZE_SYNC=1 on dev at 73a7e2a0 (which includes #2133), in release builds of settings and kit-gallery, on the same machine as before: Windows 11, RTX 4070, DX12, 239 Hz display.

    Fast left- and top-edge drags (growing and shrinking)

    • settings: the path is active and the wobble is gone. The page stays put on roughly 95% of steps, but a fast left-edge drag still flickers now and then: a frame where the page shows a step out of place. It matches what I measured with my own copy-model D3D11 prototype, where about 20–29% of steps ran past one refresh, and DWM shows a late step unsynced.

    • kit-gallery: dragging feels like roughly 20–25 fps. The occasional flicker is harder to spot at that rate, but I expect it's the same as in settings. The slowness isn't from the new path: scripted drags step at 26–29 sizes/s with RUNE_RESIZE_SYNC on and off alike, against about 155 in settings. A frame-profile build with RUNE_FRAME_LOG (path off, 106 drag frames) shows where the time goes; it's all CPU, in building the view:

      Stage Median p90
      Whole frame 37.4 ms 45.8 ms
      Build 36.8 ms 44.8 ms
      — commit 24.3 ms 33.5 ms
      — paint 8.6 ms 10.4 ms
      — layout 6.3 ms 7.5 ms
      — apply 5.8 ms 7.0 ms
      — view 4.1 ms 8.2 ms
      Encode, submit and present under 1 ms under 1.3 ms

      The sub-stages add up to more than the build because they also count builds made while handling input between frames. Every drag frame rebuilds the whole tree (whole: "new size, colour or swap chain", why: ["relayout", "instant"]) of about 11,900 nodes, and commit takes the largest share. settings has about 90 nodes and builds in under 0.1 ms.

      Also, with RUNE_RESIZE_SYNC=1 the frame log records almost nothing during a drag (6–8 lines for a whole run, against 106 with it off), so frames drawn through the new path don't seem to reach RUNE_FRAME_LOG.

    • No flash when a drag starts or ends.

    Other cases

    • With a 4K YouTube video playing on screen: same as above.
    • With an overlay open in kit-gallery: same as the kit-gallery result above.
    • Cancelling a drag with Escape: works, no flicker.
    • Moving the window by its title bar: fine, nothing changes.
    • Rapid repeated drags: same as the first case, nothing stuck or garbled.

    About captures: the occasional flicker shows up in a screen capture played back in slow motion. I can record one of a fast left-edge drag and attach it if that helps.

    A note on the private resize sync, for the record: Microsoft hasn't documented it or announced plans to (microsoft/microsoft-ui-xaml#5148 has been open for years). In practice it's Windows 11 only: IDCompositionDesktopDevicePartner6 matches 22H2 and later, the interface differs on 21H2, and on Windows 10 it doesn't hand out sync objects. Anywhere it's missing, a prototype that checks the interface's IID falls back to the documented copy-model path that #2133 ships, so that path is the right base either way.

    Unrelated, from kit-gallery's stderr: duplicate sibling key "model-scrim" under "kit-root" (and the same for "model-content").

  6. Hona commented on Nov 25, 2026

    @Hona
    Member

    The kit-gallery resize slowdown and model-scrim / model-content stderr warnings you spotted are fixed on dev in #2308 (071fa97ca):

    • What was wrong: kit-gallery's default index mounted all 183 stories at once (~11,910 nodes), and Rune's CommitKind::Relayout fast path bailed out to a full view rebuild whenever any anchored_fit overlay (including a stray unconditionally open context menu in index), aspect_fit, or pixel_aspect node was mounted. Two combobox stories also shared the "model" key and state in index, producing the duplicate model-scrim and model-content sibling keys.
    • What is on dev: CommitKind::Relayout now restores clamped anchored_fit and aspect_fit styles before re-fitting and stays on relayout when pixel_aspect is unchanged; kit-gallery's index now uses virtual_rows (~314 mounted nodes, dropping headless CPU cost from ~32.6–34.9 ms to ~0.40–0.45 ms median per resize step) and unique per-story overlay keys.
    • What to try: pull dev (071fa97ca) and repeat the same drag-resize on kit-gallery (both closed and with an overlay open).
  7. Hona commented on Nov 25, 2026

    @Hona
    Member

    Thanks for testing RUNE_RESIZE_SYNC=1 on live hardware and for the detailed numbers — that is the first live confirmation that the wobble is gone with no entry/exit flash and clean Escape, title-bar move, rapid-drag, and video behavior.

    What landed on dev in #2309 (e68fb5910)

    • Drag frames now reach RUNE_FRAME_LOG (along with SurfaceMeter, FrameReports, FrameClock, interaction timing, Trace, damage bookkeeping, and Rest), recording per-stage timings (acquire, build, upload, encode, submit, present, total) on every drag step.
    • Zero per-step shared-texture reallocations: replaced exact-size shared texture recreation on every size step with a capacited 2-slot shared texture ring (256 px growth steps) copied via CopySubresourceRegion, moved ResizeBuffers ahead of BeginPaint, and added non-blocking Poll during drags to reclaim wgpu command allocators. Off-screen --profile perf D3D12-to-D3D11 step transfer dropped from 426 µs median (120 texture allocations per 120 steps) to 28 µs median (2 allocations), though off-screen numbers leave out IDXGISwapChain1::ResizeBuffers, BeginPaint/Present(0, 0)/EndPaint, and DWM's composition latch.
    • Fallback & eligibility hardening: mid-drag failure now re-attaches DirectComposition and rolls back config so the normal swap chain reconfigures cleanly, and software (WARP) adapters and non-8-bit (HDR) formats stay on the normal path.

    Note on the occasional late step (~5% at 239 Hz): per Microsoft Learn (DXGI_SWAP_EFFECT, DXGI_SCALING), copy-model DXGI_SWAP_EFFECT_DISCARD requires DXGI_SCALING_STRETCH (only flip-model supports DXGI_SCALING_NONE), so the HWND swap chain still resizes per size step and a step that straddles a 4.2 ms refresh boundary can still land unsynced — we do not expect the documented copy-model path to eliminate every late frame at 239 Hz.

    Decision on the default & what would help next

    The path stays opt-in for now until more machines have been tested, and a public per-window ResizeSync switch is coming next so apps can ship it without an environment variable; the undocumented IDCompositionDesktopDevicePartner6 / user32 ordinal path is declined for good. Before flipping the default on Windows, reports on Intel iGPU, AMD GPU, hybrid GPU laptops (where Microsoft notes bitblt presents cost an extra cross-adapter copy), Windows 10 (22H2), mixed refresh-rate / mixed-DPI multi-monitor, HDR enabled, and dragging with an in-window playing video layer would all count — if you or anyone else following this thread has one of those setups, a report here would help.

    How to capture the drag frame log

    In PowerShell on dev at e68fb5910 or later:

    $env:RUNE_RESIZE_SYNC = "1"
    $env:RUNE_FRAME_LOG = "drag-sync-settings.jsonl"
    cargo run --release -p settings --features rune/frame-profile

    If you have a moment to share the resulting drag-sync-settings.jsonl from a fast left-edge drag — and the slow-motion capture you offered — it will show us exactly where any remaining late steps spend their time.

  8. Hona commented on Nov 25, 2026

    @Hona
    Member

    The public per-window switch has landed on dev in #2319 (6d566c196), leaving the default unchanged (ResizeSync::Auto resolves to off today, so apps that do not opt in stay on DirectComposition flip-model presentation with zero drag GPU allocations):

    use rune::{App, AppSpec, ResizeSync, el};
    
    App::new(AppSpec::new("Settings", (620.0, 520.0), || (), |_, _| el()))
        .resize_sync(ResizeSync::On)
        .run();

    The same builder is available per window on WindowSpec::resize_sync, and examples/settings now accepts --resize-sync (cargo run --release -p settings -- --resize-sync).

    RUNE_RESIZE_SYNC overrides every window without a rebuild: 1/true/yes/on forces On, 0/false/no/off forces Off (an unconditional kill switch even over ResizeSync::On), and auto selects Auto.

    Keeping this issue open until more machines have been tested before flipping ResizeSync::Auto to on by default. Reports on any of the following setups (from you or anyone else following this thread) would count toward that decision:

    • Intel integrated graphics and AMD integrated/discrete graphics
    • Hybrid GPU laptops
    • Windows 10 22H2
    • Mixed refresh rates and DPI across two monitors
    • HDR enabled
    • Dragging a window with a playing in-window video layer
  9. zAcherttp commented on Nov 26, 2026

    @zAcherttp
    Author

    Retested on dev at 66006728 (includes #2308, #2309 and #2319), release builds with --features rune/frame-profile and RUNE_RESIZE_SYNC=1, same machine: Windows 11, RTX 4070, DX12, 239 Hz.

    settings, fast left-edge drags

    Clearly better than last time. What's left is a very faint ghost: for a refresh, the right-anchored controls show a second copy about one step to the right of where they belong. It looks much smoother than before.

    Phone photo of the panel during a fast left-edge drag: the right-anchored controls show a faint second copy one step to the right

    The same late step in a screen capture of every composition (240 Hz): one refresh where the page sits closer to the window's right edge, then snaps back. Slowed to about 1/10 speed, and as a before / late step / after strip:

    Slowed capture of a fast left-edge drag: for one refresh the page shifts toward the window's right edge

    Before, late step and after: in the middle frame the cards and the Full screen button sit against the window's right edge

    From drag-sync-settings.jsonl (6 drags, 4,185 drag frames, whole: "drag resize sync"):

    Stage Median p90 p99
    Total 2.49 ms 3.16 ms 3.92 ms
    Build 0.49 ms 0.70 ms 0.86 ms
    Submit 0.27 ms 0.37 ms 0.52 ms
    Present 1.62 ms 2.16 ms 2.77 ms

    22 frames (0.5%) went over one 239 Hz refresh, and 6 of those are the first frame of a drag: the first frame of every drag has a 5–8 ms present (6–10 ms total). The very first drag after launch also took 21.9 ms in acquire, 36.8 ms total.

    kit-gallery

    Much faster after #2308, and it now drags smoothly. From its frame log (5,941 drag frames): total median 3.08 ms, p90 4.14 ms, with 9% of drag frames over a refresh. The first frame of each drag shows the same slow present (3.5–8.5 ms).

    One new, reproducible issue: the first drag after opening a dialog or a combobox flickers the whole window once. Later drags are smooth until you open a different component:

    1. Open a combobox (or a dialog).
    2. Drag an edge: the whole window flickers.
    3. Drag again: smooth.
    4. Close it and open a different component, then drag: it flickers once again.

    For a dialog, both opening it and closing it reset this, so the next drag flickers again. Neither stderr nor the frame log shows anything unusual on that drag: no fallback message, and its frame times look like any other first drag frame. So it seems to be what's drawn rather than when. One thing that might be worth checking: drag frames are drawn into a texture larger than the window, so a pass that only runs the first time after an overlay mounts (a cache refill, a layer or blur target) and doesn't clamp its viewport to the window would draw wrong content across the whole frame once.

  10. Hona commented on Nov 27, 2026

    @Hona
    Member

    Thank you @zAcherttp for the clear reproduction, captures, and frame logs! A fix for the first-drag whole-window flicker after opening/closing a dialog or combobox has landed on dev in #2646 (6594ff297).

    What was causing it

    • Unwaited first-drag Present(0, 0) before detach_dcomp: On drag exit (Leaving), Rune waits for the normal D3D12 flip-model frame to finish on the GPU before re-attaching DirectComposition (attach_root). On drag entry (BeginDrag), however, run_drag_frame immediately called detach_dcomp() (SetRoot(None) + Commit + WaitForCommitCompletion) right after the asynchronous D3D11 DXGI_SWAP_EFFECT_DISCARD Present(0, 0) returned on the CPU—before the GPU finished rendering, copying, and blitting the first drag frame into the HWND's DWM redirection surface. Whenever normal DirectComposition frames between drags changed the screen (opening or closing a dialog/scrim, or opening a different component), detaching DirectComposition early briefly exposed the stale redirection bitmap from the previous drag or startup for one refresh, flickering the whole window once while subsequent drags were smooth because the redirection bitmap already matched.
    • Additional hardening: Enabled WM_ERASEBKGND suppression before the first drag BeginPaint (rolled back on failure), disarmed any stray retained partial damage before encoding into the capacited drag target, and clamped the default scissor alongside the viewport when ActivePass::split re-opens a root pass on an oversized target texture.

    What was and was not verified

    • Verified locally off screen (Windows 11, DX12): BeginDrag ordering (set_valid_rects_active(true) -> present_shared with a live D3D11 post-present fence wait -> detach_dcomp), non-blocking steady-state drag steps, failure rollback, and bit-exact capacited-target pixel parity across stray armed damage, isolated dialog layers, El::cache, and El::backdrop_blur pass splits (cargo test -p rune --lib resize_sync, render::backdrop, render::damaged).
    • Not verified in a live window: This has not been watched on a live Windows 11 / 239 Hz display yet.

    Leaving #2113 open — when you have a chance, could you pull dev (6594ff297 or later) and retest the same kit-gallery dialog/combobox open-and-close drag sequence on your RTX 4070 / 239 Hz setup?

  11. zAcherttp commented on Nov 28, 2026

    @zAcherttp
    Author

    Retested on dev at 0aa38951 (includes #2646) with RUNE_RESIZE_SYNC=1, same machine as before (Windows 11, RTX 4070, DX12, 239 Hz). The first-drag flicker in kit-gallery is still there.

    What the flicker frame shows: the window's last frame from the previous drag. Open the basic dialog, drag, close it, open the localized combobox and drag: the flicker frame shows the basic dialog. On the next component it shows the combobox from the drag before, and so on. So for one refresh, DWM shows the redirection surface's old contents instead of the new first drag frame.

    Why waiting on the post-present fence isn't enough: the D3D11 copy waits correctly for the D3D12 render, so the new frame is the one copied. But a copy-model Present(0, 0) reaches the redirection surface through DWM, outside the D3D11 queue, so the post-present fence signal doesn't prove the blit has landed or been composed. detach_dcomp can still commit first.

    I tried three changes locally in run_drag_frame (resize_sync/frame.rs), each behind an environment variable, comparing the same build side by side:

    Change Result
    DwmFlush() right before detach_root() on the first drag frame Still flickers
    Keep the tree on for the first drag frame, detach on the second Fixes the comboboxes and the basic dialog. Still flickers on the motion/focus dialog opened right after the basic dialog, probably because the next size step can come only one composition later.
    Record DWM's composed-frame count (DWM_TIMING_INFO::cFrame from DwmGetCompositionTimingInfo) at the first drag present, keep the tree on, and detach on the first drag frame where the count has advanced by at least 2 Clean in every case I tried, including the motion/focus dialog after the basic dialog

    The working version, roughly:

    // BeginDrag: present the first frame, but don't detach yet.
    if detach_dcomp {
        first_present_frame = dwm_frame_count(); // DWM_TIMING_INFO::cFrame
    } else if let Some(at) = first_present_frame {
        // Later drag frames: detach once DWM has composed two frames since the first present,
        // so the first frame is certainly in the redirection surface.
        if dwm_frame_count().is_some_and(|now| now >= at + 2) {
            seam.detach_dcomp()?;
            first_present_frame = None;
        }
    }

    The cost is that the first step or two of each drag still show the DirectComposition tree, as on the normal path, before the drag path takes over. I couldn't see it by eye. If the count can't be read, this version never detaches during that drag, so the drag stays on the normal path instead of flickering.

    A second, smaller issue: animations freeze while a drag is held. With RUNE_RESIZE_SYNC=1, holding an edge still stops the spinner and loader in the motion/focus dialog, and moving the edge scrubs them forward. During Windows' modal size-move loop, Rune only draws when a size step arrives, and its animation wake-ups don't run. The modal loop still dispatches WM_TIMER, so I tried a timer in the dpi_drag subclass, and the animations kept running while the drag was held, with no flicker coming back (tested together with the change above):

    WM_ENTERSIZEMOVE => {
        // ... existing handling, then, for windows registered for resize sync:
        SetTimer(hwnd, DRAG_ANIM_TIMER, 8, None);
    }
    WM_TIMER if wparam == DRAG_ANIM_TIMER && moving(hwnd) => {
        // The paint reaches winit as RedrawRequested, so an animating window draws a drag frame.
        InvalidateRect(hwnd, null(), 0);
        return 0;
    }
    WM_EXITSIZEMOVE => {
        KillTimer(hwnd, DRAG_ANIM_TIMER);
        // ... existing handling
    }

    WM_TIMER is coarse (roughly 64 Hz by default), and this version invalidates even when nothing is animating, so a real version should only ask for frames while something animates.

  12. Hona commented on Nov 28, 2026

    @Hona
    Member

    Thank you @zAcherttp for isolating that down to the exact redirection-surface frame from the previous drag and confirming the two-composition DWM timing gate — that was a huge catch.

    Landed in #2753 (b1878e630 on dev):

    • Two-DWM-composition detach gate (DcompPhase::Priming): BeginDrag now presents the first drag frame (with pre-paint WM_ERASEBKGND suppression and the post-present D3D11 fence wait), records DWM_TIMING_INFO::cFrame via DwmGetCompositionTimingInfo(NULL, ...), and keeps the DirectComposition root attached until cFrame has advanced by at least 2 desktop compositions. Once detached, steady-state drag frames skip DWM timing queries. If cFrame resets (e.g. a display mode switch or DWM restart) it re-baselines for two more frames; if DWM timing is unavailable, the drag cleanly rolls back to normal DirectComposition resize instead of leaving DComp stuck attached over a frozen surface.
    • Demand-only modal drag timer: dpi_drag now arms an 8 ms WM_TIMER only on state edges while inside WM_ENTERSIZEMOVE..WM_EXITSIZEMOVE and either priming (so even a single resize step followed by a paused hold still finishes detaching after two DWM frames) or actively animating (outcome.animating). Once DComp is detached and nothing is animating—or on WM_EXITSIZEMOVE / fallback / destroy—the timer is killed immediately so static drags do zero idle invalidation.

    Verified locally: cargo check -p rune --lib and cargo test -p rune --lib resize_sync (22 passed, including pure state-machine tests for 0/1/2 DWM frame gating, counter reset, unavailable DWM count fallback, and an off-screen multi-drag GPU/seam regression test verifying Drag 2 never detaches while the redirection surface still holds Drag 1's pixels).

    Not run locally: live interactive Windows 11 border-drag testing on a 239 Hz RTX 4070 display. Keeping #2113 open for your retest on b1878e630!

  13. emmachase commented on Nov 29, 2026

    @emmachase

    I tried this on dev at 95ec635ef (so with #2646 and #2753) using RUNE_RESIZE_SYNC=1. It's a different machine from the reports above: Windows 11 25H2, RTX 4090, a 4K 240 Hz display at 200% and a 1080p 60 Hz one at 100%. I used my own app rather than settings (standard title bar, debug build with Rune at opt-level = 3).

    It's a huge improvement over sync off, but it's still a bit glitchy. Two things are left, and I can see both by eye:

    1. Every drag starts with a small jump. The first couple of size steps (roughly 25 to 40 ms) are shown unsynced before it locks in. I assume that's the window where the DirectComposition tree is still attached.
    2. The page occasionally jumps in the middle of a drag, a few times over several seconds of dragging. These look like the late steps discussed above.

    To put numbers on it, I scripted drags with real mouse input and captured every composed frame, counting the frames where the content isn't where the window frame says it should be:

    Display Dragging Sync off Sync on Overlay (see below)
    4K 240 Hz, 200% top-left corner 566 of 867 (65%) 8 of 857 (0.9%) 0 of 875
    4K 240 Hz, 200% top edge 7 of 861 (0.8%) 0 of 861
    4K 240 Hz, 200% left edge 6 of 862 (0.7%)
    1080p 60 Hz left edge 500 of 826 (61%) 10 of 839 (1.2%) 0 of 787

    With sync on, 5 or 6 of the bad frames in each run are the start of the drag and the rest are isolated ones in the middle. 1% doesn't sound like much, but a one-frame jump of the whole page is easy to notice.

    I don't think this path can get all the way to zero, since it will always be racing DWM's deadline, which matches what you said above about late steps. So here's another idea that avoids the race altogether.

    Idea: draw the drag in an overlay window

    While a border is being dragged, cloak the real window (DWMWA_CLOAK) and draw its whole picture into a separate transparent, click-through window that covers the desktop and never moves or resizes. Because the overlay never changes size, there's nothing for a frame to be out of sync with. Each present is the complete window at one size. If a frame is late, the window just trails the pointer a little more instead of showing a mismatched frame. When the drag ends, the real window is uncloaked and the overlay hidden.

    It could be a third value next to the existing ones, something like:

    App::new(spec).resize_sync(ResizeSync::Overlay).run();

    I have this working in a local build of Rune, and that's the third column in the table: 0 bad frames on the same drags with the same app.

    The catch is that the overlay has to draw everything DWM normally draws around the window: the border, rounded corners and shadow, plus the title bar if the window uses the standard one. The border and corners can be taken from a capture of the window when the drag starts, but the shadow and title bar have to be recreated to match, and none of that look is documented, so a Windows update could change it. Windows using Rune's own title bar are the easy case.

    Other downsides:

    • It's Windows 11 only.
    • It holds two desktop-sized buffers while a drag lasts.
    • Every size shown is one the app actually drew, so when frames are slow the window follows the pointer in bigger steps. In the top-left drag above, the overlay showed 167 different sizes where sync on showed about 220.
    • All the calls are documented, but it leans on a couple of undocumented names: the NonRudeHWND window property (so the shell doesn't treat the overlay as a full-screen window) and the theme class the caption buttons come from. I realize that might rule it out given the documented-APIs-only decision.
  14. bowenxuuu commented on Nov 29, 2026

    @bowenxuuu

    @Hona Hello,
    After enabling rune::ResizeSync::On, window resize dragging is noticeably smoother than before. My setup is Windows 11 26H2, NVIDIA GeForce RTX 5060 Laptop GPU with the DX12 backend.

    However, memory usage increases by roughly 12 MiB after a drag finishes, and this memory is never freed until the window is closed. From PR #2319, I understand this memory is allocated by the D3D11 device.

    It would be ideal if we could release this memory at an appropriate time. Typical users usually resize the window shortly after launching the app and rarely resize it frequently afterward, so keeping this memory permanently allocated is wasteful.

    Here is my proposal: keep the existing logic while the user is actively dragging to resize the window with the mouse held down. Once the drag completes (when the mouse button is released), release the memory associated with the D3D11 device.

  15. Hona commented on Nov 29, 2026

    @Hona
    Member

    Thank you @bowenxuuu for reporting the post-drag ~12 MiB retention — that is now fixed on dev in #2817 (a32e89e77).

    What changed

    • Release DragDevice when returning to steady-state: The copy-model D3D11 swap chain, shared render-target ring, shared fences, and lazily created D3D11 DragDevice are now owned together for the active drag only. After WM_EXITSIZEMOVE, Rune keeps them alive through State::Leaving until the post-drag D3D12 flip-model frame finishes and DirectComposition re-attaches (AttachDcomp), then drops the entire bundle cleanly so State::Idle retains zero drag GPU objects.
    • Explicit driver memory reclamation: On drop, DragDevice releases child objects in strict order, runs ID3D11DeviceContext::ClearState() + Flush() + IDXGIDevice3::Trim(), and Rune polls wgpu so dropped shared D3D12 textures are reclaimed immediately instead of waiting for a future frame while idle.
    • Lazy recreation on subsequent drags: Starting another resize drag lazily creates a fresh DragDevice on the first resize step (pure title-bar moves still allocate zero GPU objects).

    Verification

    • Verified locally off screen (Windows, DX12): cargo check -p rune --lib, wasm32 checks, scripts/file-size.sh, d3d11_interop tests (2 passed), and resize_sync unit + off-screen GPU tests with test-gpu-counters (29 passed, proving lazy acquisition, zero retained DragDevice / shared wgpu textures on idle, and clean recreation + bit-exact rendering on a second drag).
    • Not verified in a live window: Interactive Windows 11 border-drag session and Task Manager / process working-set measurement on your RTX 5060 Laptop GPU have not been run locally.

    Keeping #2113 open — when you have a chance, please pull dev (a32e89e77 or later) and let us know if your post-drag memory returns to baseline cleanly.

  16. bowenxuuu commented on Nov 29, 2026

    @bowenxuuu

    @Hona

    I ran two sets of tests on dev(a32e89e77), with the results below:
    With ResizeSync::On: ~4 MB memory increase after finishing window resize drag.
    Without ResizeSync::On: ~1 MB memory increase after finishing window resize drag.

    This is a notable improvement over the previous version, which retained roughly 12 MB of unreleased memory after drag operations. The root cause is still unknown. Even without ResizeSync::On, a 1 MB memory delta remains after resizing, implying other confounding factors that introduce measurement noise.

  17. zAcherttp commented on Nov 30, 2026

    @zAcherttp
    Author

    Retested on dev at 3592b1e3 (includes #2753 and #2817) with RUNE_RESIZE_SYNC=1, same machine as before (Windows 11, RTX 4070, DX12, 239 Hz).

    • The first-drag ghost is gone. The dialog and combobox sequence in kit-gallery no longer shows the previous drag's frame, including the motion/focus dialog opened right after the basic dialog.
    • Animations keep running while a drag is held, once the drag has started.
    • I see the same two things @emmachase describes in settings: a small jump at the start of every fast drag, and occasional one-frame jumps during longer drags.

    One gap in the drag timer: pressing a border and holding still before moving still freezes animations, because the timer only arms once the first size step starts the drag path. Holding the title bar freezes them too, and so does the same press-and-hold with RUNE_RESIZE_SYNC=0, so that part predates resize sync. I've filed it separately as #2908.

    An idea for the drag-start jump (untested): the jump is the two-composition wait happening after the first size step, while the DirectComposition tree is still attached. Windows says a size drag is starting before any size changes: WM_SYSCOMMAND with SC_SIZE (wParam & 0xFFF0), then WM_ENTERSIZEMOVE at the press. If the first copy-model frame were presented at the current size there, and the two-composition wait ran during the press, the tree could already be detached by the first size step, so no step would be shown unsynced. SC_SIZE also tells a resize from a move (SC_MOVE), so title-bar moves would still allocate nothing.

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