admin管理员组文章数量:1287554
I'm writing a Vulkan program. I have a problem with image being sometimes displayed in wrong order. Here is the part I suppose where things to go wrong. For information, I have 2 frames in flight (MAX_FRAMES_IN_FLIGHT), and 3 images (swapChainSupport.capabilities.minImageCount + 1). The two function below are called in my main loop:
// main loop content (simplified)
vcSwapChain->acquireNextImage(¤tImageIndex);
//... Do render stuff, set command buffer
vcSwapChain->submitCommandBuffers(&commandBuffer, ¤tImageIndex);
VkResult FwSwapChain::acquireNextImage(uint32_t* imageIndex) {
vkWaitForFences(device.getDevice(), 2, frameInFlightFences.data(), VK_TRUE, UINT64_MAX);
VkResult result = vkAcquireNextImageKHR(device.getDevice(), vkSwapChain, UINT64_MAX, imageAvailableSemaphores[currentFrame], VK_NULL_HANDLE, imageIndex);
return result;
}
VkResult FwSwapChain::submitCommandBuffers(const VkCommandBuffer* buffers, uint32_t* imageIndex) {
VkSubmitInfo submitInfo = {};
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
VkSemaphore waitSemaphores[] = { imageAvailableSemaphores[currentFrame] };
VkPipelineStageFlags waitStages[] = { VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT };
submitInfo.waitSemaphoreCount = 1;
submitInfo.pWaitSemaphores = waitSemaphores;
submitInfo.pWaitDstStageMask = waitStages;
submitInfomandBufferCount = 1;
submitInfo.pCommandBuffers = buffers;
VkSemaphore signalSemaphores[] = { renderFinishedSemaphores[currentFrame] };
submitInfo.signalSemaphoreCount = 1;
submitInfo.pSignalSemaphores = signalSemaphores;
vkResetFences(device.getDevice(), 1, &frameInFlightFences[currentFrame]);
if (vkQueueSubmit(device.getGraphicsQueue(), 1, &submitInfo, frameInFlightFences[currentFrame]) != VK_SUCCESS) {
throw std::runtime_error("failed to submit draw command buffer!");
}
VkPresentInfoKHR presentInfo = {};
presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
presentInfo.waitSemaphoreCount = 1;
presentInfo.pWaitSemaphores = signalSemaphores;
VkSwapchainKHR swapChains[] = { vkSwapChain };
presentInfo.swapchainCount = 1;
presentInfo.pSwapchains = swapChains;
presentInfo.pImageIndices = imageIndex;
auto result = vkQueuePresentKHR(device.getPresentQueue(), &presentInfo);
currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
return result;
}
If i set MAX_FRAMES_IN_FLIGHT to 1, then I haven't the problem.
本文标签:
版权声明:本文标题:c++ - In my Vulkan program, how to implement synchronisation to avoid displaying image in wrong order? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741311063a2371653.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论