This question is a by-product of an answer to another question: https://stackoverflow.com/a/37948367/3256878.
When a swapchain is created, its images are in VK_IMAGE_LAYOUT_UNDEFINED. In order to present they need to be in VK_IMAGE_LAYOUT_PRESENT_SRC_KHR. For this reason it seems plausible that all of them are available to the application via multiple invocations of vkAcquireNextImageKHR immediately after creating the swapchain, that is, before any rendering takes place.
I'm assuming that since the images are in VK_IMAGE_LAYOUT_UNDEFINED they should be available to the application because the presentation engine can't present them and so shouldn't be locked other than due to plain ownership. Is this assumption correct? I haven't found anything in the spec explicitly allowing or disallowing this.
I guess another way to ask the same is: can a swapchain image always be acquired by an application provided it's in VK_IMAGE_LAYOUT_UNDEFINED?
No they usually can't be acquired all at once.
The spec quote explaining that is:
Let n be the total number of images in the swapchain, m be the value of
VkSurfaceCapabilitiesKHR::minImageCount, and a be the number of presentable images that the application has currently acquired (i.e. images acquired withvkAcquireNextImageKHR, but not yet presented withvkQueuePresentKHR).vkAcquireNextImageKHRcan always succeed ifa ≤ n - mat the timevkAcquireNextImageKHRis called.[1.0.19 change]vkAcquireNextImageKHRmust not be called when ifa > n - m; in such a case, and iftimeoutisUINT64_MAX,vkAcquireNextImageKHRmay block indefinitely.vkAcquireNextImageKHRshould not be called ifa > n - mwith atimeoutofUINT64_MAX; in such a case,vkAcquireNextImageKHRmay block indefinitely.
So they can all be acquired only in the case of m = 1 if I am not mistaken.
UPDATE: With some twisting, the quote can be interpreted as such, that you can attempt to get them all (with providing non-infinite timeout), but there is no guarantee of success.
I am gonna ask that on the GitHub to verify.
RESOLUTION: I got preliminary answer on the GitHub that this interpretation is correct. That the must in the quote is perhaps meant to be should.
The thing is, you do not need to acquire them all for purposes of first transition, because in 95 % of cases reading the images after present (i.e. immediately after vkAcquire) makes no sense, so you almost always provide oldLayout==UNDEFINED (which means: whatever layout was before + GPU can scrap data).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With