Skip to content

fix(win32): release ResizeSync D3D11 DragDevice after drag finishes - #2817

Merged
Hona merged 1 commit into
devfrom
fix/resize-sync-release-drag-device
Nov 29, 2026
Merged

Hona merged 1 commit into
devfrom
fix/resize-sync-release-drag-device

Conversation

@Hona

@Hona Hona commented Nov 29, 2026

Copy link
Copy Markdown
Member

Summary

Design

  • Unified active-drag GPU ownership (ActiveDragGpu): Groups DxgiDragSwapChain, DragTargetRing, and DragDevice in strict drop order (swap_chain -> ring -> device) and unifies Effect::DropD3d11Device into Effect::ReleaseDragResources. State::Idle and State::Entering always hold zero drag GPU objects.
  • Zero-flash exit ordering: Keeps ActiveDragGpu alive across State::Leaving until the post-drag D3D12 flip-model frame finishes and Effect::AttachDcomp (SetRoot + Commit + WaitForCommitCompletion) restores steady-state DirectComposition, then runs Effect::ReleaseDragResources.
  • Clean driver memory reclamation: Reorders DragDevice fields so shared fences drop before d3d11 (and D3d11Device context drops before device/factory), runs ID3D11DeviceContext::ClearState() + Flush() + IDXGIDevice3::Trim() in DragDevice::drop, and calls non-blocking rune_gpu::health::poll after Effect::ReleaseDragResources so wgpu reclaims dropped shared D3D12 textures immediately while idle.
  • Stale device swap-chain ordering: Releases any swap chain opened on a replaced/stale D3D11 device before ensure_gpu_target drops that device.

Verification

  • cargo check -p rune --lib
  • cargo check -p rune --lib --target wasm32-unknown-unknown and cargo check -p rune-gpu --lib --target wasm32-unknown-unknown
  • cargo test -p rune --lib --features rune/test-gpu-counters,rune-gpu/test-gpu-counters resize_sync (29 passed, including new drag_device_is_acquired_lazily_dropped_on_idle_and_recreated_on_second_drag proving lazy acquisition, idle drop with zero leaked wgpu textures, and clean recreation on a second drag)
  • cargo test -p rune-gpu --lib d3d11_interop (2 passed)
  • scripts/file-size.sh (0 errors)
  • Not run locally: live interactive Windows 11 border-drag session / Task Manager working-set check on real GPU hardware.

Addresses #2113

With ResizeSync::On, DragResizeSync::release_drag_resources freed the
copy-model HWND swap chain and shared render-target ring on drag exit
but kept the lazily created D3D11 DragDevice cached until device loss or
window destruction, retaining ~12 MiB of idle memory after a single
resize drag.

- Group transient drag GPU resources (DxgiDragSwapChain, DragTargetRing,
  and DragDevice) into ActiveDragGpu with strict drop order (swap chain
  -> ring -> DragDevice) and unify Effect::DropD3d11Device into
  Effect::ReleaseDragResources so State::Idle and State::Entering retain
  zero drag GPU objects.
- Keep ActiveDragGpu alive through State::Leaving until steady-state
  DirectComposition re-attaches (Effect::AttachDcomp) before releasing
  it, preventing any exit flash.
- Flush deferred D3D11 destructions (ClearState + Flush) and call
  IDXGIDevice3::Trim in DragDevice::drop, drop shared fences before the
  D3D11 device (and D3d11Device context before device/factory), and poll
  wgpu after Effect::ReleaseDragResources so dropped shared D3D12
  textures reclaim immediately while idle.
- Add off-screen GPU and state-machine regression coverage proving lazy
  DragDevice acquisition, idle release after drag exit, and clean lazy
  recreation on a second drag.

Addresses #2113
@Hona
Hona merged commit a32e89e into dev Nov 29, 2026
5 checks passed
@Hona
Hona deleted the fix/resize-sync-release-drag-device branch November 29, 2026 12:24
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