// ================================================================================
//  Logical Device Helper Methods
// ================================================================================
/// Creates the logical device after confirming all the features and queues
/// needed are present, and returns the logical device, and a
/// [Queues](struct.Queues.html) containing all the command queues. otherwise
/// returns the [SarektError](enum.SarektError.html) that occurred.
/// TODO(issue#18) CONFIG ANISOTROPY
Logical Device Helper Methods
Creates the logical device after confirming all the features and queues
needed are present, and returns the logical device, and a
[Queues](struct.Queues.html) containing all the command queues.
Logical Device Helper Methods Creates the logical device after confirming all the features and queues needed are present and returns the logical device and a [ Queues ] ( struct . Queues . html ) containing all the command queues .
fn create_logical_device_and_queues(
    instance: &Instance, physical_device: vk::PhysicalDevice,
    surface_and_extension: &SurfaceAndExtension,
  ) -> SarektResult<(Arc<Device>, QueueFamilyIndices, Queues)> {
    let queue_family_indices =
      Self::find_queue_families(instance, physical_device, surface_and_extension)?;
    let mut indices = queue_family_indices.as_vec().unwrap();
    indices.dedup();
    let queue_prios = [1.0];
    let queue_cis: Vec<_> = indices
      .iter()
      .map(|&queue_index| {
        vk::DeviceQueueCreateInfo::builder()
          .queue_family_index(queue_index)
          .queue_priorities(&queue_prios) // MULTITHREADING All queues have the same priority, and there's one. more than 1 if multiple threads (one for each thread)
          .build()
      })
      .collect();
    let device_features = vk::PhysicalDeviceFeatures::builder()
      .sampler_anisotropy(true)
      .build();
    let enabled_extension_names = [ash::extensions::khr::Swapchain::name().as_ptr()];
    let device_ci = vk::DeviceCreateInfo::builder()
      .queue_create_infos(&queue_cis)
      .enabled_features(&device_features)
      // TODO(issue#9) OFFSCREEN only if drawing to a window
      .enabled_extension_names(&enabled_extension_names)
      .build();
    unsafe {
      // TODO(issue#9) OFFSCREEN no presentation queue needed when not presenting to
      // swapchain.
      //
      // TODO(issue#1) MULTITHREADING I would create one queue for each
      // thread, right now I'm only using one.
      let graphics_queue_family = queue_family_indices.graphics_queue_family.unwrap();
      let presentation_queue_family = queue_family_indices.presentation_queue_family.unwrap();
      let transfer_queue_family = queue_family_indices.transfer_queue_family.unwrap();
      let logical_device = instance.create_device(physical_device, &device_ci, None)?;
      let graphics_queue = logical_device.get_device_queue(graphics_queue_family, 0);
      let presentation_queue = logical_device.get_device_queue(presentation_queue_family, 0);
      let transfer_queue = logical_device.get_device_queue(transfer_queue_family, 0);
      let queues = Queues::new(graphics_queue, presentation_queue, transfer_queue);
      Ok((Arc::new(logical_device), queue_family_indices, queues))
    }
  }
fn create_logical_device_and_queues ( instance : & Instance , physical_device : vk :: PhysicalDevice , surface_and_extension : & SurfaceAndExtension , ) -> SarektResult < ( Arc < Device > , QueueFamilyIndices , Queues ) > { let queue_family_indices = Self :: find_queue_families ( instance , physical_device , surface_and_extension ) ? ; let mut indices = queue_family_indices . as_vec ( ) . unwrap ( ) ; indices . dedup ( ) ; let queue_prios = [ 1.0 ] ; let queue_cis : Vec < _ > = indices . iter ( ) . map ( | & queue_index | { vk :: DeviceQueueCreateInfo :: builder ( ) . queue_family_index ( queue_index ) . queue_priorities ( & queue_prios ) // MULTITHREADING All queues have the same priority, and there's one. more than 1 if multiple threads (one for each thread) . build ( ) } ) . collect ( ) ; let device_features = vk :: PhysicalDeviceFeatures :: builder ( ) . sampler_anisotropy ( true ) . build ( ) ; let enabled_extension_names = [ ash :: extensions :: khr :: Swapchain :: name ( ) . as_ptr ( ) ] ; let device_ci = vk :: DeviceCreateInfo :: builder ( ) . queue_create_infos ( & queue_cis ) . enabled_features ( & device_features ) // TODO(issue#9) OFFSCREEN only if drawing to a window . enabled_extension_names ( & enabled_extension_names ) . build ( ) ; unsafe { // TODO(issue#9) OFFSCREEN no presentation queue needed when not presenting to // swapchain. // // TODO(issue#1) MULTITHREADING I would create one queue for each // thread, right now I'm only using one. let graphics_queue_family = queue_family_indices . graphics_queue_family . unwrap ( ) ; let presentation_queue_family = queue_family_indices . presentation_queue_family . unwrap ( ) ; let transfer_queue_family = queue_family_indices . transfer_queue_family . unwrap ( ) ; let logical_device = instance . create_device ( physical_device , & device_ci , None ) ? ; let graphics_queue = logical_device . get_device_queue ( graphics_queue_family , 0 ) ; let presentation_queue = logical_device . get_device_queue ( presentation_queue_family , 0 ) ; let transfer_queue = logical_device . get_device_queue ( transfer_queue_family , 0 ) ; let queues = Queues :: new ( graphics_queue , presentation_queue , transfer_queue ) ; Ok ( ( Arc :: new ( logical_device ) , queue_family_indices , queues ) ) } }
Logical Device Helper Methods
Creates the logical device after confirming all the features and queues
needed are present, and returns the logical device, and a
[Queues](struct.Queues.html) containing all the command queues.
Logical Device Helper Methods Creates the logical device after confirming all the features and queues needed are present and returns the logical device and a [ Queues ] ( struct . Queues . html ) containing all the command queues .
instance
&Instance
physical_device
vk::PhysicalDevice
surface_and_extension
&SurfaceAndExtension