| 854 | } |
| 855 | |
| 856 | void Demo::draw() { |
| 857 | // Don't draw if initialization isn't complete, if the swapchain became outdated, or if the window is minimized |
| 858 | if (!initialized || !swapchain_ready || is_minimized) { |
| 859 | return; |
| 860 | } |
| 861 | |
| 862 | auto ¤t_submission = submission_resources[current_submission_index]; |
| 863 | |
| 864 | // Ensure no more than FRAME_LAG renderings are outstanding |
| 865 | const vk::Result wait_result = device.waitForFences(current_submission.fence, VK_TRUE, UINT64_MAX); |
| 866 | VERIFY(wait_result == vk::Result::eSuccess || wait_result == vk::Result::eTimeout); |
| 867 | |
| 868 | vk::Result acquire_result; |
| 869 | uint32_t current_swapchain_image_index = 0; |
| 870 | do { |
| 871 | acquire_result = device.acquireNextImageKHR(swapchain, UINT64_MAX, current_submission.image_acquired_semaphore, vk::Fence(), |
| 872 | ¤t_swapchain_image_index); |
| 873 | if (acquire_result == vk::Result::eErrorOutOfDateKHR) { |
| 874 | // demo.swapchain is out of date (e.g. the window was resized) and |
| 875 | // must be recreated: |
| 876 | resize(); |
| 877 | } else if (acquire_result == vk::Result::eSuboptimalKHR) { |
| 878 | // swapchain is not as optimal as it could be, but the platform's |
| 879 | // presentation engine will still present the image correctly. |
| 880 | break; |
| 881 | } else if (acquire_result == vk::Result::eErrorSurfaceLostKHR) { |
| 882 | inst.destroySurfaceKHR(surface); |
| 883 | create_surface(); |
| 884 | resize(); |
| 885 | } else { |
| 886 | VERIFY(acquire_result == vk::Result::eSuccess); |
| 887 | } |
| 888 | // If we minimized then stop trying to draw |
| 889 | if (!swapchain_ready) { |
| 890 | return; |
| 891 | } |
| 892 | } while (acquire_result != vk::Result::eSuccess); |
| 893 | |
| 894 | auto ¤t_swapchain_resource = swapchain_resources[current_swapchain_image_index]; |
| 895 | |
| 896 | update_data_buffer(submission_resources[current_submission_index].uniform_memory_ptr); |
| 897 | |
| 898 | draw_build_cmd(current_submission, current_swapchain_resource); |
| 899 | |
| 900 | if (separate_present_queue) { |
| 901 | build_image_ownership_cmd(current_submission, current_swapchain_resource); |
| 902 | } |
| 903 | |
| 904 | // Only reset right before submitting so we can't deadlock on an un-signalled fence that has nothing submitted to it |
| 905 | auto reset_result = device.resetFences({current_submission.fence}); |
| 906 | VERIFY(reset_result == vk::Result::eSuccess); |
| 907 | |
| 908 | // Wait for the image acquired semaphore to be signaled to ensure |
| 909 | // that the image won't be rendered to until the presentation |
| 910 | // engine has fully released ownership to the application, and it is |
| 911 | // okay to render to the image. |
| 912 | vk::PipelineStageFlags const pipe_stage_flags = vk::PipelineStageFlagBits::eColorAttachmentOutput; |
| 913 | auto protected_submit_info = vk::ProtectedSubmitInfo().setProtectedSubmit(protected_output); |
no test coverage detected