vkAcquireNextImageKHR semantics? What does timing out mean?

I am confused about the semantics of vkAcquireNextImageKHR. Specifically, under what circumstances can the function return VK_TIMEOUT? ie What could block it from not being able to acquire an image immediately? What might it wait for to happen?

It seems that an image can be acquired even if the presentation engine hasn’t finished reading from the image, and one needs to use a semaphore or fence to synchronize usage of the acquired image anyway. What am I missing?

The semantics is whatever the spec says. You get a VK_TIMEOUT if you provided non-zero and non-infinite timeout argument, and the Implementation was not able to service your request within that time.

The Vulkan is an abstraction for all possible underlying OS APIs. It is a valid choice to copy the swapchain image, schedule copying it, or use it directly by the compositor. So some implementations might be able to give you all Images (down to zero owned by the Swapchain), some might let you wait if the Swapchain has less than minImages.

The Implementation cannot return and give you a Semaphore, unless it is 200 % sure the semaphore\fence actually gets signaled (at all, or within a time past which the OS can kill you). It is called Forward Progress Guarantee.

From my (limited!) understanding, it should return VK_SUCCESS only when the queue is ready to accept the next image submission. If you have a FIFO present mode, a.k.a. v-sync, the GPU will present at the intervals your display supports (for example every 1/60th of a second). If you render faster than this, your queue will be full at some point. I doubt any implementation would allow you to acquire the same image twice if it’s not presenting yet, thus it will have to block you.

Ironically, I have recently found that on (some?) NVIDIA cards it never blocks, but the vkQueuePresentKHR call performs the synchronization instead (i.e. blocks). Unfortunately, I haven’t found a way to control it.

Edit: written while krOoze posted, sorry for the duplication :wink: