Repository navigation
Conversation
…e changed SUBOPTIMAL from vkAcquireNextImageKHR or vkQueuePresentKHR marked the presenter stale, so the next frame waited for the queue to go idle and recreated the swapchain even on an unchanged surface. The surface queries and choices of recreate() now live in choose(); after a SUBOPTIMAL result the next submit compares a fresh choice with the one the swapchain was built from and rebuilds only when they differ. OUT_OF_DATE, the lost surface path and the minimised path are unchanged. vk_presenter_sync_test injects SUBOPTIMAL after successful acquires and presents: 12 on an unchanged window now rebuild nothing (main: 6 swapchain creations and 6 vkQueueWaitIdle), and one after a resize still follows the new client size. Reported by cherryinbubbles-ops in ItsNotRexed#7231.
|
Independent Windows + NVIDIA GPU test of Setup: Windows 11 x64, MSVC 19.44.35220 (
AI-assisted review/test. |
|
Independent native Windows validation check of 4abe9b3e. RTX 3080 Ti, NVIDIA 621.35, Vulkan SDK 1.4.363.0. The focused AI-assisted. |
|
Tested I used the PR's regression test against its parent
All six patched runs recovered the expected swapchain extent after a real window resize and reported zero validation errors. The seven-test presentation group also passed on each GPU ( AI-assisted verification. Synthetic fixtures only. |
byPreaZy
left a comment
There was a problem hiding this comment.
Review (static): the SUBOPTIMAL handling is correct. Checked the edge cases the diff does not spell out:
chosen_is always populated before it is compared: the first swapchain goes throughrecreate()(ok_ = recreate(true, false)inprepare), and the zero-extent minimized path leavesswapchain_null so thesuboptimal_ && swapchain_guard skips the compare anyway.suboptimal_self-clears inside the guard (suboptimal_ = falsebeforechoose()), andrecreate()clears it again on success, so a failedchoose()cannot spin: it setsstale_once and the existing recreate-retry path takes over.choose()is side-effect free (surface queries +find_tear_modeonly), so calling it speculatively on the suboptimal check is safe, and the extravkGetPhysicalDeviceSurfaceCapabilitiesKHRper suboptimal episode is one call per event, not per frame in the steady state.SwapchainChoice::tearis redundant inoperator==(derived from mode/min_images/usage/extent) but harmless.
The test's two cases cover both directions: unchanged surface keeps the swapchain (0 creates, 0 wait-idles over 12 presents), resized surface still rebuilds. LGTM pending the maintainer's GPU run; AI-assisted (Devin), no local run.
|
Independent Windows/MSVC 19.44, RTX 5060 driver 32.0.16.1088 verification: #7391 diff applied cleanly to main 8575d36 audit checkout (already contains unrelated #7125 test correction and #7357 handle fix). Rebuilt vk_presenter_sync_test, RelWithDebInfo, ran exit 0. Output confirms 12 SUBOPTIMAL advisories on unchanged surface rebuilt nothing, and SUBOPTIMAL after resize rebuilt at new extent. Other sync/capture/concurrent-present regression checks passed. Validation layer unavailable, no validation coverage claimed. Existing C4189 and TEMP MSB8029 warnings remain. Synthetic windows only, no game files. AI-assisted (Codex). |
|
Tested
AI-assisted (Claude Code). |
|
Windows GPU check on AMD: Radeon RX 9060 XT, driver 32.0.32015.7029, Windows 11 x64, MSVC 14.44, RelWithDebInfo, Vulkan SDK 1.4.363.0, no game files. PR head applied on
Independent AMD confirmation of the RTX 4070 numbers: SUBOPTIMAL no longer forces a swapchain rebuild when the chosen parameters are unchanged, and a real surface change still rebuilds. AI-assisted (Devin). |
Claimed in the coordination issue: #7231 (comment), from @cherryinbubbles-ops's finding #7231 (comment) (thanks). This is a separate implementation; the patch attached to the finding was not used.
What and why
VK_SUBOPTIMAL_KHRis advisory: the image was acquired or presented, and the swapchain still works.VulkanPresenter::submit_nowtreated it likeVK_ERROR_OUT_OF_DATE_KHR. Acquire and present both setstale_, so the next frame ranrecreate(): avkQueueWaitIdle, then a new swapchain, even when the new one would be identical. A driver or compositor that keeps reporting SUBOPTIMAL therefore stalls the queue and rebuilds the swapchain on every frame.Now:
recreate()'s surface queries and choices move intochoose(vsync, srgb, hdr, SwapchainChoice&): extent (including the0xFFFFFFFF/extent_fn_path), surface format and colour space, HDR, present mode, image usage, min image count, pre-transform, composite alpha and, withLEONIDA_SWAPCHAIN_MAINTENANCE1, the tear mode.recreate()calls it and fills the sameVkSwapchainCreateInfoKHRas before. A successful recreate keeps the choice inchosen_.suboptimal_instead ofstale_.submit_nowrunschoose()with the current swapchain's request (vsync_,swapchain_srgb_,swapchain_hdr_req_). It setsstale_, so the existing path rebuilds, only when the choice differs fromchosen_or a surface query fails. Otherwise the swapchain is kept, with no queue wait.VK_ERROR_OUT_OF_DATE_KHR, the lost-surface recovery from presenter: recover a lost surface instead of a sticky E_FAIL #6832, the minimised (zero-extent) path, and every recreate triggered by a vsync, sRGB or HDR change.Related: #7344 handles the opposite case, rebuilding when the client size changed but the driver has not reported SUBOPTIMAL or OUT_OF_DATE yet. The two changes are independent, and this branch merges cleanly with #7344's head (
git merge-tree).The five comment lines in
recreate()that the diff shows as added are existing comments; the function moved belowchoose(), and their text is unchanged.Tests
New step at the end of
runtime/test/vk_presenter_sync_test.cpp. Its synthetic driver layer now also hooksvkAcquireNextImageKHR,vkCreateSwapchainKHRandvkQueueWaitIdle. SUBOPTIMAL is injected only after the real call succeeded, so the frame really was acquired or presented.vkCreateSwapchainKHR, 0vkQueueWaitIdleand the same extent.vkCreateSwapchainKHR.Measured on an NVIDIA GeForce RTX 4070, driver 617.42, Windows 11, MSVC 14.43, RelWithDebInfo:
vkCreateSwapchainKHRvkQueueWaitIdlemain8575d36edwith only the test applied, 12 injected SUBOPTIMAL, unchanged windowThe
maincounts are the same in 3 of 3 runs. With only the test applied, the new step fails onmainatswapchain_creates == 0.ctest -R "present|swapchain"(7 tests:vk_presenter_capture_colour,vk_presenter_sync,d3d12_present,xbox_present,dxgi_swapchain,dxgi_swapchain_count,xbox_present_readback_size): 7/7 pass with this PR on8575d36edin 3 of 3 runs and again after rebasing onb2801e26e; 7/7 onmainwithout it.gta6rtbuilds. The only/W4warning in these files is the existing C4189 (deviceunused inmark_surface_lost), which is onmaintoo.Checklist
docs/design.md, with how it was confirmed. (n/a: no translator change)