Skip to content

vulkan_present: rebuild the swapchain when the window's client size changes, not only when the driver says so - #7344

Open
Pierrot1398 wants to merge 1 commit into
ItsNotRexed:mainfrom
Pierrot1398:runtime/present-follow-client-size
Open

Pierrot1398 wants to merge 1 commit into
ItsNotRexed:mainfrom
Pierrot1398:runtime/present-follow-client-size

Conversation

@Pierrot1398

Copy link
Copy Markdown

Claimed in the coordination issue as: new item, #7231 (comment)

What and why

VulkanPresenter::submit rebuilt the swapchain only when the driver reported the old one unfit (acquire VK_SUBOPTIMAL_KHR/VK_ERROR_OUT_OF_DATE_KHR, present out of date/suboptimal). The Vulkan spec doesn't require a driver to report that on the first present after a window resize, and NVIDIA on Win32 can keep returning VK_SUCCESS for a few presents, so those frames were shown at the old size. A D3D12/DXGI title expects presentation to follow its window promptly. This was note 3 of the review of #7246 (which made the test tolerate the delay).

Now, per present and before the existing recreate check:

  1. read the window's client size through extent_fn_ (already GetClientRect for window presenters, runtime/shims/d3d12_vulkan_device.cpp), which is cheap;
  2. only if it differs from extent_, call vkGetPhysicalDeviceSurfaceCapabilitiesKHR;
  3. mark the swapchain stale when currentExtent is left to the application (0xFFFFFFFF) or differs from extent_.

Step 3 keeps a window whose client size never matches the surface (DPI virtualisation) from rebuilding on every present: the surface has to agree first. Nothing changes when extent_fn_ is not set, when there is no swapchain (minimised), or when the swapchain is already stale.

Known limit: with currentExtent left to the application and a client size outside the surface's min/max extent, recreate() clamps the extent, so the sizes keep differing and the swapchain is rebuilt each present. I haven't seen a surface like that; a follow-up could compare with the clamped size.

Related: #7246 (test side of the same delay); the Wine/Hyprland claim in #7231 (tests compare with GetClientRect) is test-side and doesn't touch this file.

Tested

Windows 11 Pro 26300, NVIDIA GeForce RTX 5060 Ti, driver 621.24 (32.0.16.2124), MSVC (VS 18 Build Tools) RelWithDebInfo, Vulkan headers fetched with -DLEONIDA_VULKAN_HEADERS_FETCH=ON, on main 4da521d.

  • Full ctest -j4: 233/234 pass. The one failure, d3d12_vulkan_device at d3d12_vulkan_device_test.cpp:6564 (tiles == 1), fails the same way without this change (2/2 runs on main): it is TEST-1649 (slot 78 after d3d12_xs: route the public HLE's Xbox device slots 48/73/78/79/80 #6935), not this PR.
  • 5 runs each, all pass: xbox_present_test, d3d12_present_test, vk_presenter_sync_test, vk_presenter_capture_colour_test, xbox_present_readback_size_test.
  • Not shown by a test: no test here forces a driver that lags after a resize, so the new path is exercised only when one does.

AI-assisted: yes (Claude Code)

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: runtime change, no translator rule)

🤖 Generated with Claude Code

…hanges, not only when the driver says so

Some drivers (NVIDIA on Win32) keep returning VK_SUCCESS for a few presents after a resize, so frames were
shown at the old size. Per present, compare the client area (extent_fn_, GetClientRect) with the swapchain
extent; only when it differs ask the surface, and mark the swapchain stale when the surface's currentExtent
agrees (or is left to the application), so a client size that never matches the surface does not rebuild
every present. Follow-up of ItsNotRexed#7246's review (note 3).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MartinIndra02

Copy link
Copy Markdown

Independent Windows + NVIDIA GPU test of 1bd6f919b: pass.

Setup: Windows 11 x64, MSVC 19.44.35220 (RelWithDebInfo, Windows SDK 10.0.26100.0), NVIDIA GeForce RTX 3080 (driver 32.0.16.2124 / 621.24), Vulkan SDK 1.4.363.1, no game files.

  • xbox_present_test.exe: xbox_present_test: all cases pass (exit 0), including window resized 320x240 -> 400x300 -> 200x150 -> 320x240 between composed presents: ok.
  • d3d12_present_test.exe: PASS (exit 0) — M0: 70 frames cleared and presented through the Xbox-ABI proxy on Vulkan, swapchain recreated on resize, colour confirmed in the presented images.

AI-assisted review/test.

@gut0to

gut0to commented Nov 23, 2026

Copy link
Copy Markdown

Independent Windows/MSVC validation on 1bd6f919bca4897b2f08ef42a5e809500fefd309:

  • git diff --check HEAD^ HEAD is clean.
  • Configured an isolated VS 2022 x64 RelWithDebInfo build with the pinned Vulkan headers and compiled all affected targets.
  • Passed CTest 5/5: xbox_present_readback_size, vk_presenter_capture_colour, vk_presenter_sync, d3d12_present, and xbox_present.

Code review agrees with the guard ordering: the client extent is read only for a live, non-stale swapchain with extent_fn_; surface capabilities are queried only on a size difference; and marking stale requires either application-chosen extent or a surface extent different from the current swapchain. This preserves the documented DPI-virtualisation safeguard while covering the delayed-driver-notification path.

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.

3 participants