| 822 | } |
| 823 | |
| 824 | void vkRenderer::drawFrame() { |
| 825 | uint32_t imageIndex; |
| 826 | VkResult result = vkAcquireNextImageKHR(device, swapChain, std::numeric_limits<uint64_t>::max(), |
| 827 | imageAvailableSemaphore, VK_NULL_HANDLE, &imageIndex); |
| 828 | |
| 829 | if (result == VK_ERROR_OUT_OF_DATE_KHR) { |
| 830 | recreateSwapChain(); |
| 831 | return; |
| 832 | } else if (result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR) { |
| 833 | throw std::runtime_error("failed to acquire swap chain image!"); |
| 834 | } |
| 835 | |
| 836 | VkSubmitInfo submitInfo = {}; |
| 837 | submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 838 | |
| 839 | VkSemaphore waitSemaphores[] = {imageAvailableSemaphore}; |
| 840 | VkPipelineStageFlags waitStages[] = {VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT}; |
| 841 | submitInfo.waitSemaphoreCount = 1; |
| 842 | submitInfo.pWaitSemaphores = waitSemaphores; |
| 843 | submitInfo.pWaitDstStageMask = waitStages; |
| 844 | |
| 845 | submitInfo.commandBufferCount = 1; |
| 846 | submitInfo.pCommandBuffers = &commandBuffers[imageIndex]; |
| 847 | |
| 848 | VkSemaphore signalSemaphores[] = {renderFinishedSemaphore}; |
| 849 | submitInfo.signalSemaphoreCount = 1; |
| 850 | submitInfo.pSignalSemaphores = signalSemaphores; |
| 851 | |
| 852 | if (vkQueueSubmit(graphicsQueue, 1, &submitInfo, VK_NULL_HANDLE) != VK_SUCCESS) { |
| 853 | throw std::runtime_error("failed to submit draw command buffer!"); |
| 854 | } |
| 855 | |
| 856 | VkPresentInfoKHR presentInfo = {}; |
| 857 | presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; |
| 858 | |
| 859 | presentInfo.waitSemaphoreCount = 1; |
| 860 | presentInfo.pWaitSemaphores = signalSemaphores; |
| 861 | |
| 862 | VkSwapchainKHR swapChains[] = {swapChain}; |
| 863 | presentInfo.swapchainCount = 1; |
| 864 | presentInfo.pSwapchains = swapChains; |
| 865 | |
| 866 | presentInfo.pImageIndices = &imageIndex; |
| 867 | |
| 868 | result = vkQueuePresentKHR(presentQueue, &presentInfo); |
| 869 | |
| 870 | if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR) { |
| 871 | recreateSwapChain(); |
| 872 | } else if (result != VK_SUCCESS) { |
| 873 | throw std::runtime_error("failed to present swap chain image!"); |
| 874 | } |
| 875 | |
| 876 | if (enableValidationLayers) { |
| 877 | vkQueueWaitIdle(presentQueue); |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | VkShaderModule vkRenderer::createShaderModule(const std::vector<char> &code) { |
nothing calls this directly
no outgoing calls
no test coverage detected