SHARE
TWEET

Untitled

a guest Nov 16th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     pub fn do_draw(
  2.         &mut self,
  3.         _window: &winit::window::Window,
  4.         _time_state: &TimeState
  5.     )
  6.         -> Result<(), ash::vk::Result>
  7.     {
  8.         let frame_fence = self.swapchain.in_flight_fences[self.sync_frame_index];
  9.  
  10.         // Wait if two frame are already in flight
  11.         unsafe {
  12.             self.device.logical_device.wait_for_fences(&[frame_fence], true, std::u64::MAX).unwrap();
  13.             self.device.logical_device.reset_fences(&[frame_fence]).unwrap();
  14.         }
  15.  
  16.         let (present_index, _is_suboptimal) = unsafe {
  17.             self.swapchain
  18.                 .swapchain_loader
  19.                 .acquire_next_image(
  20.                     self.swapchain.swapchain,
  21.                     std::u64::MAX,
  22.                     self.swapchain.image_available_semaphores[self.sync_frame_index],
  23.                     vk::Fence::null(),
  24.                 )?
  25.         };
  26.  
  27.         let wait_semaphores = [self.swapchain.image_available_semaphores[self.sync_frame_index]];
  28.         let signal_semaphores = [self.swapchain.render_finished_semaphores[self.sync_frame_index]];
  29.  
  30.         let wait_dst_stage_mask = [vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT];
  31.         let command_buffers = [self.pipeline.command_buffers[present_index as usize]];
  32.  
  33.         //add fence to queue submit
  34.         let submit_info = [
  35.             vk::SubmitInfo::builder()
  36.                 .wait_semaphores(&wait_semaphores)
  37.                 .signal_semaphores(&signal_semaphores)
  38.                 .wait_dst_stage_mask(&wait_dst_stage_mask)
  39.                 .command_buffers(&command_buffers)
  40.                 .build()
  41.         ];
  42.  
  43.         unsafe {
  44.             self.device.logical_device
  45.                 .queue_submit(self.device.queues.graphics_queue, &submit_info, frame_fence)
  46.                 .expect("queue submit failed.");
  47.         }
  48.  
  49.         let wait_semaphors = [self.swapchain.render_finished_semaphores[self.sync_frame_index]];
  50.         let swapchains = [self.swapchain.swapchain];
  51.         let image_indices = [present_index];
  52.         let present_info = vk::PresentInfoKHR::builder()
  53.             .wait_semaphores(&wait_semaphors) // &base.rendering_complete_semaphore)
  54.             .swapchains(&swapchains)
  55.             .image_indices(&image_indices);
  56.  
  57.         unsafe {
  58.             self.swapchain.swapchain_loader
  59.                 .queue_present(self.device.queues.present_queue, &present_info)
  60.                 .unwrap();
  61.         }
  62.  
  63.         self.sync_frame_index = (self.sync_frame_index + 1) % MAX_FRAMES_IN_FLIGHT;
  64.  
  65.         Ok(())
  66.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top