Skip to content

feat(win32): add opt-in drag-only synchronized resize path (RUNE_RESIZE_SYNC=1) - #2133

Merged
Hona merged 1 commit into
devfrom
feat/2113-win32-drag-resize-sync
Nov 25, 2026
Merged

Hona merged 1 commit into
devfrom
feat/2113-win32-drag-resize-sync

Conversation

@Hona

@Hona Hona commented Nov 25, 2026

Copy link
Copy Markdown
Member

Refs #2113

Adds an opt-in (RUNE_RESIZE_SYNC=1, off by default), drag-only synchronized resize path on Windows using public Microsoft-documented APIs only. No new public Rust API is added, and when RUNE_RESIZE_SYNC is unset or 0, Windows presentation, Slot pacing, WM_NCCALCSIZE, and WM_ERASEBKGND remain unchanged with zero D3D11 devices, shared textures, or second swap chains created.

State machine & data flow

stateDiagram-v2
    [*] --> Idle
    Idle --> Entering: WM_ENTERSIZEMOVE (eligible)
    Entering --> Idle: WM_EXITSIZEMOVE (pure move) / Handover / Hide / Destroy / DeviceLost
    Entering --> Dragging: first Resize -> BeginDrag ok
    Entering --> Idle: DragFailed
    Dragging --> Dragging: Resize / Redraw -> RenderDragFrame
    Dragging --> Leaving: WM_EXITSIZEMOVE -> RequestExitFrame + WakeAt(500ms)
    Dragging --> Idle: Handover / Hide / Destroy / DeviceLost / zero size
    Leaving --> Idle: ExitFrameCompleted / TimerDue / Handover / Hide / Destroy / DeviceLost
    Leaving --> Entering: WM_ENTERSIZEMOVE (re-entry)
Loading
flowchart LR
    RT[Rune Runtime + Renderer] --> D12[D3D12 Shared Texture<br/>D3D12_HEAP_FLAG_SHARED]
    D12 -->|Queue::Signal ready| F[Shared Fence<br/>ID3D12Fence <-> ID3D11Fence]
    F -->|Context::Wait ready| D11[D3D11 CopyResource]
    D11 -->|BeginPaint / Present 0 / EndPaint| SC[D3D11 DXGI_SWAP_EFFECT_DISCARD<br/>HWND Swap Chain]
    D11 -->|Context::Signal release| F
Loading

Changes

  • Shared D3D12/D3D11 interop (crates/rune-gpu/src/d3d11_interop.rs): Lazy System32-only D3D11CreateDevice on the active D3D12 adapter LUID, ID3D12Fence <-> ID3D11Fence shared fences, and ID3D12Resource <-> ID3D11Texture2D shared render targets; shared with crates/rune-media/src/video/windows/gpu.rs.
  • Drag state machine & WVR_VALIDRECTS (crates/rune/src/window/win32/resize_sync/machine.rs): Explicit rune::machine state machine (Idle, Entering, Dragging, Leaving) with Attempt-fenced exit timer, strictly gated to WM_ENTERSIZEMOVE..WM_EXITSIZEMOVE on opaque app windows with a settled Rune-owned Handover (SurfaceMode::Handed). Excludes transparent windows (WS_EX_NOREDIRECTIONBITMAP), overlays, DxgiFromHwnd, and SurfaceMode::Cpu / HandingOver / Rebinding.
  • Off-screen GPU plumbing & narrow HWND seam (crates/rune/src/window/win32/resize_sync/{gpu,present}.rs, resize_sync.rs): Renders drag frames into a D3D12 shared texture (TextureUses::PRESENT / COMMON handoff), signals shared fences, and presents via a D3D11 DXGI_SWAP_EFFECT_DISCARD HWND swap chain inside WM_PAINT (BeginPaint/EndPaint) behind DragSeam, with zero presents to the hidden D3D12 composition swap chain during drag.
  • DirectComposition & Win32 subclass hooks (crates/rune/src/platform/win32/{dcomp_handover,dpi_drag,frame}.rs): Handover::detach_root / attach_root (IDCompositionTarget::SetRoot), WVR_VALIDRECTS for both custom-frame and standard-frame windows, WM_ERASEBKGND suppression, and scoped WM_PAINT trampoline — all inactive unless RUNE_RESIZE_SYNC=1 and in Dragging. Slot during resize (crates/rune/src/window/host/draw.rs) is untouched; no SetOffsetX/SetOffsetY or undocumented APIs are used.
  • Docs & changelog: Documented RUNE_RESIZE_SYNC=1 in crates/rune/README.md and added changelog/unreleased/2026-11-25-windows-drag-resize-sync.md.

Scope & live-window status

  • Off-screen proven: State machine transitions/exclusions/all abort exits/re-entry/timers, WVR_VALIDRECTS rect math, opt-in-off zero-allocation guarantee (test-gpu-counters), and real-adapter D3D12-to-D3D11 shared-texture/fence creation, cleanup, and bit-exact pixel parity (Bgra8Unorm and Bgra8UnormSrgb across resize).
  • Not run in a live window: The thin HWND-bound Win32DragSeam (CreateSwapChainForHwnd(DISCARD), BeginPaint/EndPaint, SetRoot(None)/SetRoot(root) during a live WM_ENTERSIZEMOVE..WM_EXITSIZEMOVE drag) has not been observed on a live Windows 11 display yet; the path stays off by default until live verification.

@Hona
Hona merged commit 14e80f9 into dev Nov 25, 2026
1 check passed
@Hona
Hona deleted the feat/2113-win32-drag-resize-sync branch November 25, 2026 05:32
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