From 7c072d60e2068c71b757e54a067428ce6187399b Mon Sep 17 00:00:00 2001 From: Florian RICHER Date: Thu, 7 Nov 2024 22:14:01 +0100 Subject: [PATCH] Begin add use_layers [not work] --- Cargo.lock | 136 ++++++++++++++++++++++++++++++++++++++ Cargo.toml | 6 +- src/main.rs | 2 + src/vulkan/utils.rs | 51 ++++++++++++++ src/vulkan/vk_instance.rs | 7 +- 5 files changed, 199 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d729efb..425c1e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -31,6 +31,15 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "android-activity" version = "0.6.0" @@ -58,6 +67,55 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04" +[[package]] +name = "anstream" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" + +[[package]] +name = "anstyle-parse" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125" +dependencies = [ + "anstyle", + "windows-sys 0.59.0", +] + [[package]] name = "arrayref" version = "0.3.9" @@ -235,6 +293,12 @@ dependencies = [ "objc", ] +[[package]] +name = "colorchoice" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" + [[package]] name = "combine" version = "4.6.7" @@ -333,6 +397,29 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f25c0e292a7ca6d6498557ff1df68f32c99850012b6ea401cf8daf771f22ff53" +[[package]] +name = "env_filter" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "humantime", + "log", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -409,6 +496,12 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "indexmap" version = "2.6.0" @@ -419,6 +512,12 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + [[package]] name = "jni" version = "0.21.1" @@ -934,12 +1033,43 @@ dependencies = [ "bitflags 2.6.0", ] +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + [[package]] name = "rust_ash_test" version = "0.1.0" dependencies = [ "ash", "ash-window", + "env_logger", + "log", "winit", ] @@ -1172,6 +1302,12 @@ version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "version_check" version = "0.9.5" diff --git a/Cargo.toml b/Cargo.toml index e765a81..8c27b75 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,4 +8,8 @@ publish = false [dependencies] winit = { version = "0.30", features = [ "rwh_06" ] } ash = { version = "0.38", default-features = false, features = ["linked", "debug", "std"] } -ash-window = "0.13" \ No newline at end of file +ash-window = "0.13" + +# Log and tracing +log = "0.4" +env_logger = "0.11.5" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 7e8cde1..85004fb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,8 @@ mod display; mod vulkan; fn main() { + env_logger::init(); + let event_loop = EventLoop::new().unwrap(); let mut app = display::App::default(); diff --git a/src/vulkan/utils.rs b/src/vulkan/utils.rs index e69de29..9ac9a87 100644 --- a/src/vulkan/utils.rs +++ b/src/vulkan/utils.rs @@ -0,0 +1,51 @@ +use std::ffi::CStr; +use ash::{vk, Entry}; + +pub fn use_layers( + entry: &Entry, + layers_to_select: Vec<&str> +) -> Vec<*const std::ffi::c_char> { + let layers_available = unsafe { + entry + .enumerate_instance_layer_properties() + .unwrap_or_default() + }; + + let mut selected_layers = Vec::<&CStr>::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()); + } + + log::info!( + "\t{:?}\tImplementation version: {}\tVulkan Version: {}\tDescription: {:?}", + l.layer_name_as_c_str().unwrap_or_default(), + l.implementation_version, + print_version(l.spec_version), + l.description_as_c_str().unwrap_or_default() + ); + } + log::info!(""); // Add blank line + + log::info!("Layers to select ({}):", layers_to_select.len()); + for l in layers_to_select { + let selected = selected_layers.contains(&l); + log::info!("\t{:?}\tSelected: {}", l, selected); + } + log::info!(""); // Add blank line + + selected_layers.iter().map(|sl| sl.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) + ) +} \ No newline at end of file diff --git a/src/vulkan/vk_instance.rs b/src/vulkan/vk_instance.rs index b634cbb..2ef59d0 100644 --- a/src/vulkan/vk_instance.rs +++ b/src/vulkan/vk_instance.rs @@ -1,6 +1,7 @@ use std::ffi::CString; use ash::{Instance, vk, Entry}; use winit::raw_window_handle::{HasDisplayHandle}; +use crate::vulkan::utils::use_layers; use crate::vulkan::VkPhysicalDevice; pub struct VkInstance { @@ -13,8 +14,10 @@ impl VkInstance { let entry = Entry::linked(); // Layers - let layers_available = unsafe { entry.enumerate_instance_layer_properties().unwrap_or_default() }; - let layer_names = layers_available.iter().map(|layer| layer.layer_name.as_ptr()).collect::>(); + let layers = use_layers(&entry, vec![ + "VK_LAYER_MANGOHUD_overlay_x86_64" + ]); + let layer_names = Vec::<*const std::ffi::c_char>::new(); // Extensions let mut extension_names =