Repository navigation
vulkan_present: rebuild the swapchain when the window's client size changes, not only when the driver says so - #7344
Conversation
…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>
|
Independent Windows + NVIDIA GPU test of Setup: Windows 11 x64, MSVC 19.44.35220 (
AI-assisted review/test. |
|
Independent Windows/MSVC validation on
Code review agrees with the guard ordering: the client extent is read only for a live, non-stale swapchain with |
Claimed in the coordination issue as: new item, #7231 (comment)
What and why
VulkanPresenter::submitrebuilt the swapchain only when the driver reported the old one unfit (acquireVK_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 returningVK_SUCCESSfor 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:
extent_fn_(alreadyGetClientRectfor window presenters,runtime/shims/d3d12_vulkan_device.cpp), which is cheap;extent_, callvkGetPhysicalDeviceSurfaceCapabilitiesKHR;currentExtentis left to the application (0xFFFFFFFF) or differs fromextent_.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
currentExtentleft 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, onmain4da521d.ctest -j4: 233/234 pass. The one failure,d3d12_vulkan_deviceatd3d12_vulkan_device_test.cpp:6564(tiles == 1), fails the same way without this change (2/2 runs onmain): 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.xbox_present_test,d3d12_present_test,vk_presenter_sync_test,vk_presenter_capture_colour_test,xbox_present_readback_size_test.AI-assisted: yes (Claude Code)
Checklist
docs/design.md, with how it was confirmed. (n/a: runtime change, no translator rule)🤖 Generated with Claude Code