@@ -8,7 +8,7 @@ use core::{
88} ; 
99
1010use  arrayvec:: ArrayVec ; 
11- use  ash:: { ext,  khr ,   vk} ; 
11+ use  ash:: { ext,  vk} ; 
1212use  hashbrown:: hash_map:: Entry ; 
1313use  parking_lot:: Mutex ; 
1414
@@ -489,122 +489,6 @@ struct CompiledStage {
489489} 
490490
491491impl  super :: Device  { 
492-     pub ( super )  unsafe  fn  create_swapchain ( 
493-         & self , 
494-         surface :  & super :: Surface , 
495-         config :  & crate :: SurfaceConfiguration , 
496-         provided_old_swapchain :  Option < super :: Swapchain > , 
497-     )  -> Result < super :: Swapchain ,  crate :: SurfaceError >  { 
498-         profiling:: scope!( "Device::create_swapchain" ) ; 
499-         let  functor = khr:: swapchain:: Device :: new ( & surface. instance . raw ,  & self . shared . raw ) ; 
500- 
501-         let  old_swapchain = match  provided_old_swapchain { 
502-             Some ( osc)  => osc. raw , 
503-             None  => vk:: SwapchainKHR :: null ( ) , 
504-         } ; 
505- 
506-         let  color_space = if  config. format  == wgt:: TextureFormat :: Rgba16Float  { 
507-             // Enable wide color gamut mode 
508-             // Vulkan swapchain for Android only supports DISPLAY_P3_NONLINEAR_EXT and EXTENDED_SRGB_LINEAR_EXT 
509-             vk:: ColorSpaceKHR :: EXTENDED_SRGB_LINEAR_EXT 
510-         }  else  { 
511-             vk:: ColorSpaceKHR :: SRGB_NONLINEAR 
512-         } ; 
513- 
514-         let  original_format = self . shared . private_caps . map_texture_format ( config. format ) ; 
515-         let  mut  raw_flags = vk:: SwapchainCreateFlagsKHR :: empty ( ) ; 
516-         let  mut  raw_view_formats:  Vec < vk:: Format >  = vec ! [ ] ; 
517-         if  !config. view_formats . is_empty ( )  { 
518-             raw_flags |= vk:: SwapchainCreateFlagsKHR :: MUTABLE_FORMAT ; 
519-             raw_view_formats = config
520-                 . view_formats 
521-                 . iter ( ) 
522-                 . map ( |f| self . shared . private_caps . map_texture_format ( * f) ) 
523-                 . collect ( ) ; 
524-             raw_view_formats. push ( original_format) ; 
525-         } 
526- 
527-         let  mut  info = vk:: SwapchainCreateInfoKHR :: default ( ) 
528-             . flags ( raw_flags) 
529-             . surface ( surface. raw ) 
530-             . min_image_count ( config. maximum_frame_latency  + 1 )  // TODO: https://github.com/gfx-rs/wgpu/issues/2869 
531-             . image_format ( original_format) 
532-             . image_color_space ( color_space) 
533-             . image_extent ( vk:: Extent2D  { 
534-                 width :  config. extent . width , 
535-                 height :  config. extent . height , 
536-             } ) 
537-             . image_array_layers ( config. extent . depth_or_array_layers ) 
538-             . image_usage ( conv:: map_texture_usage ( config. usage ) ) 
539-             . image_sharing_mode ( vk:: SharingMode :: EXCLUSIVE ) 
540-             . pre_transform ( vk:: SurfaceTransformFlagsKHR :: IDENTITY ) 
541-             . composite_alpha ( conv:: map_composite_alpha_mode ( config. composite_alpha_mode ) ) 
542-             . present_mode ( conv:: map_present_mode ( config. present_mode ) ) 
543-             . clipped ( true ) 
544-             . old_swapchain ( old_swapchain) ; 
545- 
546-         let  mut  format_list_info = vk:: ImageFormatListCreateInfo :: default ( ) ; 
547-         if  !raw_view_formats. is_empty ( )  { 
548-             format_list_info = format_list_info. view_formats ( & raw_view_formats) ; 
549-             info = info. push_next ( & mut  format_list_info) ; 
550-         } 
551- 
552-         let  result = { 
553-             profiling:: scope!( "vkCreateSwapchainKHR" ) ; 
554-             unsafe  {  functor. create_swapchain ( & info,  None )  } 
555-         } ; 
556- 
557-         // doing this before bailing out with error 
558-         if  old_swapchain != vk:: SwapchainKHR :: null ( )  { 
559-             unsafe  {  functor. destroy_swapchain ( old_swapchain,  None )  } 
560-         } 
561- 
562-         let  raw = match  result { 
563-             Ok ( swapchain)  => swapchain, 
564-             Err ( error)  => { 
565-                 return  Err ( match  error { 
566-                     vk:: Result :: ERROR_SURFACE_LOST_KHR 
567-                     | vk:: Result :: ERROR_INITIALIZATION_FAILED  => crate :: SurfaceError :: Lost , 
568-                     vk:: Result :: ERROR_NATIVE_WINDOW_IN_USE_KHR  => { 
569-                         crate :: SurfaceError :: Other ( "Native window is in use" ) 
570-                     } 
571-                     // We don't use VK_EXT_image_compression_control 
572-                     // VK_ERROR_COMPRESSION_EXHAUSTED_EXT 
573-                     other => super :: map_host_device_oom_and_lost_err ( other) . into ( ) , 
574-                 } ) ; 
575-             } 
576-         } ; 
577- 
578-         let  images =
579-             unsafe  {  functor. get_swapchain_images ( raw)  } . map_err ( super :: map_host_device_oom_err) ?; 
580- 
581-         // NOTE: It's important that we define the same number of acquire/present semaphores 
582-         // as we will need to index into them with the image index. 
583-         let  acquire_semaphores = ( 0 ..=images. len ( ) ) 
584-             . map ( |i| { 
585-                 super :: SwapchainAcquireSemaphore :: new ( & self . shared ,  i) 
586-                     . map ( Mutex :: new) 
587-                     . map ( Arc :: new) 
588-             } ) 
589-             . collect :: < Result < Vec < _ > ,  _ > > ( ) ?; 
590- 
591-         let  present_semaphores = ( 0 ..=images. len ( ) ) 
592-             . map ( |i| Arc :: new ( Mutex :: new ( super :: SwapchainPresentSemaphores :: new ( i) ) ) ) 
593-             . collect :: < Vec < _ > > ( ) ; 
594- 
595-         Ok ( super :: Swapchain  { 
596-             raw, 
597-             functor, 
598-             device :  Arc :: clone ( & self . shared ) , 
599-             images, 
600-             config :  config. clone ( ) , 
601-             acquire_semaphores, 
602-             next_acquire_index :  0 , 
603-             present_semaphores, 
604-             next_present_time :  None , 
605-         } ) 
606-     } 
607- 
608492    /// # Safety 
609493/// 
610494/// - `vk_image` must be created respecting `desc` 
0 commit comments