MCPcopy Create free account
hub / github.com/NVIDIA/cuda-samples / drawFrame

Method drawFrame

cpp/5_Domain_Specific/simpleVulkanMMAP/VulkanBaseApp.cpp:1634–1704  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1632}
1633
1634void VulkanBaseApp::drawFrame()
1635{
1636 size_t currentFrameIdx = m_currentFrame % MAX_FRAMES_IN_FLIGHT;
1637 vkWaitForFences(m_device, 1, &m_inFlightFences[currentFrameIdx], VK_TRUE, std::numeric_limits<uint64_t>::max());
1638
1639 uint32_t imageIndex;
1640 VkResult result = vkAcquireNextImageKHR(m_device,
1641 m_swapChain,
1642 std::numeric_limits<uint64_t>::max(),
1643 m_imageAvailableSemaphores[currentFrameIdx],
1644 VK_NULL_HANDLE,
1645 &imageIndex);
1646 if (result == VK_ERROR_OUT_OF_DATE_KHR) {
1647 recreateSwapChain();
1648 }
1649 else if (result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR) {
1650 throw std::runtime_error("Failed to acquire swap chain image!");
1651 }
1652
1653 updateUniformBuffer(imageIndex, m_currentFrame);
1654
1655 VkSubmitInfo submitInfo = {};
1656 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1657
1658 std::vector<VkSemaphore> waitSemaphores;
1659 std::vector<VkPipelineStageFlags> waitStages;
1660
1661 waitSemaphores.push_back(m_imageAvailableSemaphores[currentFrameIdx]);
1662 waitStages.push_back(VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT);
1663 getWaitFrameSemaphores(waitSemaphores, waitStages);
1664
1665 submitInfo.waitSemaphoreCount = (uint32_t)waitSemaphores.size();
1666 submitInfo.pWaitSemaphores = waitSemaphores.data();
1667 submitInfo.pWaitDstStageMask = waitStages.data();
1668
1669 submitInfo.commandBufferCount = 1;
1670 submitInfo.pCommandBuffers = &m_commandBuffers[imageIndex];
1671
1672 std::vector<VkSemaphore> signalSemaphores;
1673 getSignalFrameSemaphores(signalSemaphores);
1674 signalSemaphores.push_back(m_renderFinishedSemaphores[currentFrameIdx]);
1675 submitInfo.signalSemaphoreCount = (uint32_t)signalSemaphores.size();
1676 submitInfo.pSignalSemaphores = signalSemaphores.data();
1677
1678 vkResetFences(m_device, 1, &m_inFlightFences[currentFrameIdx]);
1679
1680 if (vkQueueSubmit(m_graphicsQueue, 1, &submitInfo, m_inFlightFences[currentFrameIdx]) != VK_SUCCESS) {
1681 throw std::runtime_error("failed to submit draw command buffer!");
1682 }
1683
1684 VkPresentInfoKHR presentInfo = {};
1685 presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
1686 presentInfo.waitSemaphoreCount = 1;
1687 presentInfo.pWaitSemaphores = &m_renderFinishedSemaphores[currentFrameIdx];
1688
1689 VkSwapchainKHR swapChains[] = {m_swapChain};
1690 presentInfo.swapchainCount = 1;
1691 presentInfo.pSwapchains = swapChains;

Callers

nothing calls this directly

Calls 3

updateUniformBufferFunction · 0.85
maxFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected