diff --git a/src/vulkan/utils.rs b/src/vulkan/utils.rs index 9ac9a87..6f2b527 100644 --- a/src/vulkan/utils.rs +++ b/src/vulkan/utils.rs @@ -1,4 +1,4 @@ -use std::ffi::CStr; +use std::ffi::CString; use ash::{vk, Entry}; pub fn use_layers( @@ -11,13 +11,18 @@ pub fn use_layers( .unwrap_or_default() }; - let mut selected_layers = Vec::<&CStr>::new(); + let mut selected_layers = Vec::::new(); log::info!("Available layers ({}):", layers_available.len()); for l in layers_available { - let layer_name = l.layer_name_as_c_str().unwrap_or_default(); - if layers_to_select.iter().any(|ln| (*ln).eq(layer_name)) { - selected_layers.push(layer_name.clone()); + let layer_name = l + .layer_name_as_c_str() + .unwrap_or_default() + .to_string_lossy() + .into_owned(); + + if layers_to_select.iter().any(|ln| (*ln).eq(&layer_name)) { + selected_layers.push(layer_name); } log::info!( @@ -30,22 +35,24 @@ pub fn use_layers( } log::info!(""); // Add blank line - log::info!("Layers to select ({}):", layers_to_select.len()); + log::info!("Layers wanted ({}):", layers_to_select.len()); for l in layers_to_select { - let selected = selected_layers.contains(&l); + let selected = selected_layers.iter().any(|sl| sl.eq(l)); log::info!("\t{:?}\tSelected: {}", l, selected); } log::info!(""); // Add blank line - selected_layers.iter().map(|sl| sl.as_ptr()).collect() + selected_layers.iter().map(|sl| { + let c_string = CString::new(sl.clone().as_bytes()).unwrap(); + c_string.as_ptr() + }).collect() } pub fn print_version(version: u32) -> String { format!( - "{}.{}.{}.{}", + "{}.{}.{}", vk::api_version_major(version), vk::api_version_minor(version), - vk::api_version_patch(version), - vk::api_version_variant(version) + vk::api_version_patch(version) ) -} \ No newline at end of file +} diff --git a/src/vulkan/vk_instance.rs b/src/vulkan/vk_instance.rs index 2ef59d0..b52f383 100644 --- a/src/vulkan/vk_instance.rs +++ b/src/vulkan/vk_instance.rs @@ -15,9 +15,9 @@ impl VkInstance { // Layers let layers = use_layers(&entry, vec![ - "VK_LAYER_MANGOHUD_overlay_x86_64" + "VK_LAYER_MANGOHUD_overlay_x86_64", + "VK_LAYER_NV_optimus" ]); - let layer_names = Vec::<*const std::ffi::c_char>::new(); // Extensions let mut extension_names = @@ -50,7 +50,7 @@ impl VkInstance { // Instance Info let create_info = vk::InstanceCreateInfo::default() .application_info(&appinfo) - .enabled_layer_names(&layer_names) + .enabled_layer_names(&layers) .enabled_extension_names(&extension_names) .flags(create_flags);