I am new to vulkan and following the vulkan-tutorial . In the chapter about swapchain and multiple frames in flight ( frames_in_flight ) there is something I dont understand.
The variable imageIndex
gets set by the function vkAcquireNextImageKHR
uint32_t imageIndex;
vkAcquireNextImageKHR(device, swapChain, UINT64_MAX, imageAvailableSemaphores[currentFrame], VK_NULL_HANDLE, &imageIndex);
and the variable currentFrame
gets incremented each frame
currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
The imageIndex
variable just gets used for the pImageIndices
field of the VkPresentInfoKHR
struct and for the indexing into the std::vector<VkFramebuffer>
.
All other vectors eg the VkFence
or VkCommandBuffer
are indexed with the currentFrame
variable.
What exactly is the defferece between imageIndex
and currentFrame
and why do I need to keep track of woth?
The difference is:
vkAcquireNextImageKHR::imageIndex
is "random". It can return any number in any order.
The currentFrame
changes strictly in round-robin fashion. Additionally the max-count may differ from swapchain image count.
You would use vkAcquireNextImageKHR::imageIndex
for things tied to a specific swapchain image. And you would use currentFrame
for things tied to the sequence of frames (eg odd frames vs even frames).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.