/// When the target dimensions or requirements change, we must recreate a
/// bunch of stuff to remain compatible and continue rendering to the new
/// surface.
When the target dimensions or requirements change, we must recreate a
bunch of stuff to remain compatible and continue rendering to the new
surface.
When the target dimensions or requirements change we must recreate a bunch of stuff to remain compatible and continue rendering to the new surface .
unsafe fn do_recreate_swapchain(&mut self, width: u32, height: u32) -> SarektResult<()> {
    let instance = &self.vulkan_core.instance;
    let logical_device = &self.vulkan_device_structures.logical_device;
    let physical_device = self.vulkan_device_structures.physical_device;
    let shader_store = &self.shader_store;
    let present_mode = self.config.present_mode;
    // Procedure: Wait for the device to be idle, make new Swapchain (recycling old
    // one), cleanup old resources and recreate them:
    // * ImageViews
    // * Render Passes
    // * Graphics Pipelines
    // * Framebuffers
    // * Command Buffers.
    logical_device.device_wait_idle()?;
    let (old_swapchain, old_images) = self.render_target_bundle.recreate_swapchain(
      &self.vulkan_core,
      &self.vulkan_device_structures,
      width,
      height,
      present_mode,
    )?;
    self.cleanup_swapchain(Some((&old_images, old_swapchain)))?;
    let new_format = self.render_target_bundle.swapchain_and_extension.format;
    let new_extent = self.render_target_bundle.extent;
    let resolve_attachment = if !matches!(self.config.msaa_config.samples, NumSamples::One) {
      Some(ResolveAttachment::new(
        &self.buffer_image_store,
        (width, height),
        new_format.try_into()?,
        self.config.msaa_config.samples,
      )?)
    } else {
      None
    };
    let depth_buffer = DepthAttachment::new(
      &instance,
      physical_device,
      &self.buffer_image_store,
      (width, height),
      self.config.msaa_config.samples,
    )?;
    self.pipelines.recreate_renderpasses(
      logical_device,
      new_format,
      self.config.msaa_config.samples,
    )?;
    let (vertex_shader_handle, fragment_shader_handle, descriptor_set_layouts) =
      self.pipelines.take_shaders_and_layouts();
    self.pipelines.recreate_framebuffers(
      logical_device,
      resolve_attachment.as_ref(),
      &depth_buffer,
      &self.render_target_bundle.render_targets,
      new_extent,
    )?;
    self.pipelines.recreate_base_pipeline_bundle(
      logical_device,
      shader_store,
      new_extent,
      resolve_attachment,
      depth_buffer,
      &self.config.msaa_config,
      descriptor_set_layouts.unwrap(),
      vertex_shader_handle.unwrap(),
      fragment_shader_handle.unwrap(),
    )?;
    self.main_descriptor_pools = Self::create_main_descriptor_pools(
      instance,
      physical_device,
      logical_device,
      &self.render_target_bundle.render_targets,
    )?;
    // Reset render_frame_count
    self.current_frame_num.set(0);
    // Reset command buffers and rerun setup.
    logical_device.reset_command_pool(
      self.main_gfx_command_pool,
      vk::CommandPoolResetFlags::empty(),
    )?;
    self.draw_synchronization.recreate_semaphores()?;
    self.setup_next_main_command_buffer()?;
    Ok(())
  }
unsafe fn do_recreate_swapchain ( & mut self , width : u32 , height : u32 ) -> SarektResult < ( ) > { let instance = & self . vulkan_core . instance ; let logical_device = & self . vulkan_device_structures . logical_device ; let physical_device = self . vulkan_device_structures . physical_device ; let shader_store = & self . shader_store ; let present_mode = self . config . present_mode ; // Procedure: Wait for the device to be idle, make new Swapchain (recycling old // one), cleanup old resources and recreate them: // * ImageViews // * Render Passes // * Graphics Pipelines // * Framebuffers // * Command Buffers. logical_device . device_wait_idle ( ) ? ; let ( old_swapchain , old_images ) = self . render_target_bundle . recreate_swapchain ( & self . vulkan_core , & self . vulkan_device_structures , width , height , present_mode , ) ? ; self . cleanup_swapchain ( Some ( ( & old_images , old_swapchain ) ) ) ? ; let new_format = self . render_target_bundle . swapchain_and_extension . format ; let new_extent = self . render_target_bundle . extent ; let resolve_attachment = if ! matches ! ( self config msaa_config samples NumSamples One ) { Some ( ResolveAttachment :: new ( & self . buffer_image_store , ( width , height ) , new_format . try_into ( ) ? , self . config . msaa_config . samples , ) ? ) } else { None } ; let depth_buffer = DepthAttachment :: new ( & instance , physical_device , & self . buffer_image_store , ( width , height ) , self . config . msaa_config . samples , ) ? ; self . pipelines . recreate_renderpasses ( logical_device , new_format , self . config . msaa_config . samples , ) ? ; let ( vertex_shader_handle , fragment_shader_handle , descriptor_set_layouts ) = self . pipelines . take_shaders_and_layouts ( ) ; self . pipelines . recreate_framebuffers ( logical_device , resolve_attachment . as_ref ( ) , & depth_buffer , & self . render_target_bundle . render_targets , new_extent , ) ? ; self . pipelines . recreate_base_pipeline_bundle ( logical_device , shader_store , new_extent , resolve_attachment , depth_buffer , & self . config . msaa_config , descriptor_set_layouts . unwrap ( ) , vertex_shader_handle . unwrap ( ) , fragment_shader_handle . unwrap ( ) , ) ? ; self . main_descriptor_pools = Self :: create_main_descriptor_pools ( instance , physical_device , logical_device , & self . render_target_bundle . render_targets , ) ? ; // Reset render_frame_count self . current_frame_num . set ( 0 ) ; // Reset command buffers and rerun setup. logical_device . reset_command_pool ( self . main_gfx_command_pool , vk :: CommandPoolResetFlags :: empty ( ) , ) ? ; self . draw_synchronization . recreate_semaphores ( ) ? ; self . setup_next_main_command_buffer ( ) ? ; Ok ( ( ) ) }
When the target dimensions or requirements change, we must recreate a
bunch of stuff to remain compatible and continue rendering to the new
surface.
When the target dimensions or requirements change we must recreate a bunch of stuff to remain compatible and continue rendering to the new surface .
&mut self
width
u32
height
u32