简体   繁体   English

C++ Vulkan 交换链 image_index 与 current_frame

[英]C++ Vulkan swapchain image_index vs current_frame

I am new to vulkan and following the vulkan-tutorial .我是 vulkan 的新手并遵循vulkan-tutorial In the chapter about swapchain and multiple frames in flight ( frames_in_flight ) there is something I dont understand.在关于交换链和飞行中的多个帧( frames_in_flight )的章节中,有一些我不明白的东西。

The variable imageIndex gets set by the function vkAcquireNextImageKHR变量imageIndex由函数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 = (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> . imageIndex变量仅用于VkPresentInfoKHR结构的pImageIndices字段和对std::vector<VkFramebuffer>的索引。

All other vectors eg the VkFence or VkCommandBuffer are indexed with the currentFrame variable.所有其他向量,例如VkFenceVkCommandBuffer都使用currentFrame变量进行索引。

What exactly is the defferece between imageIndex and currentFrame and why do I need to keep track of woth? imageIndexcurrentFrame之间的差异到底是什么,为什么我需要跟踪 woth?

The difference is:区别在于:

vkAcquireNextImageKHR::imageIndex is "random". vkAcquireNextImageKHR::imageIndex是“随机的”。 It can return any number in any order.它可以以任何顺序返回任何数字。

The currentFrame changes strictly in round-robin fashion. currentFrame以循环方式严格更改。 Additionally the max-count may differ from swapchain image count.此外,最大计数可能与交换链图像计数不同。

You would use vkAcquireNextImageKHR::imageIndex for things tied to a specific swapchain image.您可以使用vkAcquireNextImageKHR::imageIndex来处理与特定交换链图像相关的内容。 And you would use currentFrame for things tied to the sequence of frames (eg odd frames vs even frames).您可以将currentFrame用于与帧序列相关的事物(例如奇数帧与偶数帧)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM