Skip to content

fix(win32): wait for first drag Present before detaching DComp and clamp split pass scissor - #2646

Merged
Hona merged 1 commit into
devfrom
fix/win32-resize-sync-entry-flicker
Nov 27, 2026
Merged

Hona merged 1 commit into
devfrom
fix/win32-resize-sync-entry-flicker

Conversation

@Hona

@Hona Hona commented Nov 27, 2026

Copy link
Copy Markdown
Member

Addresses #2113.

Root cause

During Windows synchronized drag resize (ResizeSync::On / RUNE_RESIZE_SYNC=1), the post-drag exit path (Leaving -> Idle) waits for the GPU to finish presenting the normal D3D12 flip-model frame before re-attaching DirectComposition (attach_root). The drag-entry path (BeginDrag) did not have the symmetric wait:

  • DxgiDragSwapChain::copy_and_present queued D3D11 Wait(ready) -> CopySubresourceRegion -> Present(0, 0) (asynchronous GPU blt into the HWND's DWM redirection surface) and returned immediately.
  • run_drag_frame immediately called detach_dcomp() (SetRoot(None) + Commit + WaitForCommitCompletion) before the GPU finished rendering, copying, and blitting the first drag frame into the redirection surface.
  • Whenever normal DirectComposition frames between drags had updated the window (opening or closing a dialog, opening a combobox, or scrolling to a different component), detaching DirectComposition early exposed the stale redirection bitmap from the previous drag or startup for one refresh, flickering the whole window once. Subsequent drags without UI changes were smooth because the redirection bitmap already matched.

Additionally, run_drag_frame enabled WM_ERASEBKGND suppression only after the first BeginPaint, disarmed retained damage only after draw_ui, and ActivePass::split left the default scissor unclamped when re-opening a root pass on an oversized capacited target texture.

Changes

  • Post-present GPU wait on BeginDrag only (crates/rune/src/window/win32/resize_sync/{gpu,present,frame}.rs): add a reusable Win32 event handle on DragDevice, signal release + Flush strictly after Present(0, 0) when wait_for_present is true (BeginDrag only; zero overhead on steady-state drag steps), and wait on the fence right after EndPaint before calling detach_dcomp().
  • Pre-paint erase suppression & stray damage disarm (crates/rune/src/window/win32/resize_sync/frame.rs): enable set_valid_rects_active(true) before the first BeginPaint (rolled back via Event::DragFailed -> ReleaseDragResources on failure) and call renderer.damage_drawn() before draw_ui so drag frames never enter draw_armed against a capacited target.
  • Oversized-target scissor clamp on pass split (crates/rune/src/render/pass.rs): clamp both viewport and default scissor to (size[0].min(src_tex.width()), size[1].min(src_tex.height())) when ActivePass::split re-opens a render pass with scissor: None.
  • Regression tests (crates/rune/src/window/win32/resize_sync/entry_tests.rs): verify BeginDrag ordering (set_valid_rects_active(true) -> present_shared(wait_for_present=true) + live D3D11 fence wait -> detach_dcomp), steady-state non-blocking steps, failure rollback, and bit-exact capacited-target pixel parity across stray armed damage (matching capacity dimensions), isolated dialog layers, El::cache, and El::backdrop_blur pass splits on both Bgra8Unorm and Bgra8UnormSrgb.

Verification

  • Verified locally on Windows 11 (NVIDIA RTX 5070 Ti DX12) off-screen: cargo test -p rune --lib resize_sync (20 passed), cargo test -p rune --lib render::backdrop (6 passed), cargo test -p rune --lib render::damaged (4 passed), and cargo check -p rune --lib --tests.
  • Not verified in a live window: live HWND drag-resize on a 239 Hz display still needs confirmation on Windows: steady live resize by syncing each drag frame with the window's size step #2113.

…amp split pass scissor

Addresses #2113.\n\nOn BeginDrag, run_drag_frame previously detached DirectComposition\n(SetRoot(None) + Commit + WaitForCommitCompletion) immediately after the\nasynchronous D3D11 DXGI_SWAP_EFFECT_DISCARD Present(0, 0) returned to the\nCPU, without waiting for the GPU to finish rendering, copying, and\nblitting the first drag frame into the HWND redirection surface. When\nnormal frames between drags had changed the window (for example opening or\nclosing a dialog or combobox), detaching DirectComposition early briefly\nrevealed the stale redirection surface from the previous drag or startup,\ncausing a single whole-window flicker on the first drag while subsequent\ndrags were smooth.\n\nChanges:\n- Add a reusable auto-reset Win32 event on DragDevice with\n  signal_post_present() + wait_for_release(), invoked once on BeginDrag\n  (never on steady-state drag steps) right after EndPaint and strictly\n  before detach_dcomp(), making drag entry symmetric with drag exit.\n- Enable WVR_VALIDRECTS / WM_ERASEBKGND suppression before the first\n  BeginPaint on BeginDrag (rolled back on DragFailed).\n- Disarm any stray retained partial damage before encoding a drag frame so\n  draw_ui always renders whole into the capacited shared target.\n- Clamp both viewport and default scissor to the active sub-rect in\n  ActivePass::split when re-opening a root pass on an oversized target.
@Hona
Hona merged commit 6594ff2 into dev Nov 27, 2026
2 checks passed
@Hona
Hona deleted the fix/win32-resize-sync-entry-flicker branch November 27, 2026 16:03
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.

1 participant