A swapchain rebuild that fails is retried with the swapchain the failed call retired as oldSwapchain (VUID-VkSwapchainCreateInfoKHR-oldSwapchain-01933) #208
Labels
No labels
claude:blocked
claude:done
claude:failed
claude:in-progress
claude:ready
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Catcrafts/Crafter.Graphics#208
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
When
vkCreateSwapchainKHRfails during a rebuild, the swapchain it was given asoldSwapchainis retired all the same, andswapChainstill names it.RebuildSwapchainleavesswapchainRebuildPendingset, so the nextRender()(or aResizeorSetPresentModeoutside a frame) tries the rebuild again, and that retry passes the same, now retired, swapchain asoldSwapchain, which valid usage forbids. Line numbers refer toe1ca2fd.Details
implementations/Crafter.Graphics-Window.cpp:820:RebuildSwapchainsetsswapchainRebuildPending = truebefore it rebuilds and clears it only once the swapchain is made (:844), so a rebuild that throws is tried again.:1765VkSwapchainKHR oldSwapchain = swapChain;and:1854swapchainCI.oldSwapchain = oldSwapchain;inCreateSwapchain. The old swapchain's image views are destroyed before the create (:1862-1865).:1870-1872: the new swapchain is made into a local and goes intoswapChainonly when the call succeeds, so after a failureswapChainstill names the old swapchain. Beforee1ca2fdthe call wrote into the member itself, which then had undefined contents after a failure: no better for the retry.RebuildIfDeferred(:913), first thing in everyRender()(:1431) and after its present (:1676).Resize(:814) andSetPresentMode(:938) outside a frame callRebuildSwapchainthemselves, sinceswapChainis not null.chapters/VK_KHR_surface/wsi.adocat Vulkan-Docsv1.4.369, lines 6119-6121: "Upon calling vkCreateSwapchainKHR with an oldSwapchain that is not VK_NULL_HANDLE, oldSwapchain is retired -- even if creation of the new swapchain fails." And VUID-VkSwapchainCreateInfoKHR-oldSwapchain-01933, lines 6306-6309: "If oldSwapchain is not VK_NULL_HANDLE, oldSwapchain must be a non-retired swapchain associated with the native window referred to by surface".Found by reading the code, in the pre-push review of #169's fix; not reproduced, since no test makes
vkCreateSwapchainKHRitself fail. The retry is invalid usage, so what a driver does with it is undefined; the validation layer would report 01933.Suggested fix
When
vkCreateSwapchainKHRfails with anoldSwapchain, destroy that swapchain where a successful create already destroys it (:1875-1876, after the same wait for the queue) and leave the window with no swapchain, so that the retry passesVK_NULL_HANDLE. A nullswapChainnow means "not made yet" toResize(:802),SetPresentMode(:929) and the configure listener (hasSwapchain,:2073), andimageswould still hold the destroyed swapchain's images, so those would readswapchainRebuildPendingtoo: a window whose rebuild failed takes a size and a present mode as one with a swapchain does, and draws nothing until the retry succeeds.