diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp index b62fd6c..1166cfd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -612,7 +612,43 @@ private: } void drawFrame() { - // XXX workout syncronization + uint32_t imageIndex; + vkAcquireNextImageKHR(device, swapChain, std::numeric_limits<uint64_t>::max(), + imageAvailableSemaphore, VK_NULL_HANDLE, &imageIndex); + + VkSubmitInfo submitInfo = {}; + submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + + VkSemaphore waitSemaphores[] = {imageAvailableSemaphore}; + VkPipelineStageFlags waitStages[] = {VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT}; + + submitInfo.waitSemaphoreCount = 1; + submitInfo.pWaitSemaphores = waitSemaphores; + submitInfo.pWaitDstStageMask = waitStages; + + submitInfo.commandBufferCount = 1; + submitInfo.pCommandBuffers = &commandBuffers[imageIndex]; + + VkSemaphore signalSemaphores[] = {renderFinishedSemaphore}; + submitInfo.signalSemaphoreCount = 1; + submitInfo.pSignalSemaphores = signalSemaphores; + + if (vkQueueSubmit(graphicsQueue, 1, &submitInfo, VK_NULL_HANDLE) != 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[] = {swapChain}; + presentInfo.swapchainCount =1; + presentInfo.pSwapchains = swapChains; + + presentInfo.pImageIndices = &imageIndex; + + vkQueuePresentKHR(presentQueue, &presentInfo); } void createInstance() { |