| 1638 | } |
| 1639 | #ifdef _VK_TIMELINE_SEMAPHORE |
| 1640 | void VulkanBaseApp::drawFrame() |
| 1641 | { |
| 1642 | static uint64_t waitValue = 0; |
| 1643 | static uint64_t signalValue = 1; |
| 1644 | |
| 1645 | size_t currentFrameIdx = m_currentFrame % MAX_FRAMES_IN_FLIGHT; |
| 1646 | |
| 1647 | // Wait for this frame's fence to avoid VUID-vkAcquireNextImageKHR-semaphore-01779 |
| 1648 | // Ensures previous frame's GPU work completes before reusing per-frame semaphores |
| 1649 | vkWaitForFences(m_device, 1, &m_inFlightFences[currentFrameIdx], VK_TRUE, std::numeric_limits<uint64_t>::max()); |
| 1650 | |
| 1651 | VkSemaphoreWaitInfo semaphoreWaitInfo = {}; |
| 1652 | semaphoreWaitInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_WAIT_INFO; |
| 1653 | semaphoreWaitInfo.pSemaphores = &m_vkTimelineSemaphore; |
| 1654 | semaphoreWaitInfo.semaphoreCount = 1; |
| 1655 | semaphoreWaitInfo.pValues = &waitValue; |
| 1656 | vkWaitSemaphores(m_device, &semaphoreWaitInfo, std::numeric_limits<uint64_t>::max()); |
| 1657 | |
| 1658 | // Use separate binary semaphores for swapchain sync to avoid VUID-01779 |
| 1659 | // Timeline semaphore (m_vkTimelineSemaphore) is dedicated to Vulkan-CUDA interop |
| 1660 | uint32_t imageIndex; |
| 1661 | VkResult result = vkAcquireNextImageKHR(m_device, |
| 1662 | m_swapChain, |
| 1663 | std::numeric_limits<uint64_t>::max(), |
| 1664 | m_vkImageAcquiredSemaphores[currentFrameIdx], |
| 1665 | VK_NULL_HANDLE, |
| 1666 | &imageIndex); |
| 1667 | if (result == VK_ERROR_OUT_OF_DATE_KHR) { |
| 1668 | recreateSwapChain(); |
| 1669 | return; |
| 1670 | } |
| 1671 | else if (result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR) { |
| 1672 | throw std::runtime_error("Failed to acquire swap chain image!"); |
| 1673 | } |
| 1674 | |
| 1675 | // Reset the fence for this frame |
| 1676 | vkResetFences(m_device, 1, &m_inFlightFences[currentFrameIdx]); |
| 1677 | |
| 1678 | updateUniformBuffer(imageIndex); |
| 1679 | |
| 1680 | VkSubmitInfo submitInfo = {}; |
| 1681 | submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 1682 | |
| 1683 | std::vector<VkSemaphore> waitSemaphores; |
| 1684 | std::vector<VkPipelineStageFlags> waitStages; |
| 1685 | |
| 1686 | waitSemaphores.push_back(m_vkImageAcquiredSemaphores[currentFrameIdx]); |
| 1687 | waitStages.push_back(VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT); |
| 1688 | waitSemaphores.push_back(m_vkTimelineSemaphore); |
| 1689 | waitStages.push_back(VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT); |
| 1690 | |
| 1691 | submitInfo.waitSemaphoreCount = (uint32_t)waitSemaphores.size(); |
| 1692 | submitInfo.pWaitSemaphores = waitSemaphores.data(); |
| 1693 | submitInfo.pWaitDstStageMask = waitStages.data(); |
| 1694 | |
| 1695 | submitInfo.commandBufferCount = 1; |
| 1696 | submitInfo.pCommandBuffers = &m_commandBuffers[imageIndex]; |
| 1697 |
nothing calls this directly
no test coverage detected