use std::collections::HashSet; use anyhow::Result; use vulkanalia::prelude::v1_0::*; use vulkanalia::Device; use crate::app::{AppData, VALIDATION_ENABLED, VALIDATION_LAYER}; use crate::physical_device::{QueueFamilyIndices, DEVICE_EXTENSIONS}; pub(crate) unsafe fn create_logical_device( instance: &Instance, data: &mut AppData, ) -> Result { let indices = QueueFamilyIndices::get(instance, data, data.physical_device)?; let mut unique_indices = HashSet::new(); unique_indices.insert(indices.graphics); unique_indices.insert(indices.present); let queue_priorities = &[1.0]; let queue_infos = unique_indices .iter() .map(|i| { vk::DeviceQueueCreateInfo::builder() .queue_family_index(*i) .queue_priorities(queue_priorities) }) .collect::>(); let mut layers = vec![]; if VALIDATION_ENABLED { layers.push(VALIDATION_LAYER.as_ptr()); } let features = vk::PhysicalDeviceFeatures::builder() .sampler_anisotropy(data.setting_anisotropy) .sample_rate_shading(data.setting_sample_shading); let extensions = DEVICE_EXTENSIONS .iter() .map(|n| n.as_ptr()) .collect::>(); let info = vk::DeviceCreateInfo::builder() .queue_create_infos(&queue_infos) .enabled_layer_names(&layers) .enabled_extension_names(&extensions) .enabled_features(&features); let device = instance.create_device(data.physical_device, &info, None)?; data.graphics_queue = device.get_device_queue(indices.graphics, 0); data.present_queue = device.get_device_queue(indices.present, 0); Ok(device) }