From 8c042108b988a19cb9209bc6241d60905418b430 Mon Sep 17 00:00:00 2001 From: Ilya Zlobintsev Date: Mon, 19 Oct 2020 08:34:53 +0300 Subject: [PATCH] Added basic vulkan info --- cli/src/main.rs | 2 +- daemon/Cargo.toml | 3 +- daemon/src/daemon.rs | 4 +- daemon/src/gpu_controller.rs | 75 +++++++--- daemon/src/lib.rs | 3 + gui/src/main.rs | 17 +++ gui/src/main_window.glade | 139 +++++++++++++++++- gui/src/main_window.glade~ | 278 ----------------------------------- 8 files changed, 219 insertions(+), 302 deletions(-) delete mode 100644 gui/src/main_window.glade~ diff --git a/cli/src/main.rs b/cli/src/main.rs index 154c2ca..90fb009 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -16,7 +16,7 @@ fn main() { println!("VRAM: {}/{}", gpu_stats.mem_used, gpu_stats.mem_total); } Opt::Info => { - let gpu_info = daemon::get_gpu_info(); + let gpu_info = daemon::get_gpu_info().unwrap(); println!("GPU Vendor: {}", gpu_info.gpu_vendor); println!("GPU Model: {}", gpu_info.card_model); println!("Driver in use: {}", gpu_info.driver); diff --git a/daemon/Cargo.toml b/daemon/Cargo.toml index f7dd826..088fcc6 100644 --- a/daemon/Cargo.toml +++ b/daemon/Cargo.toml @@ -8,4 +8,5 @@ edition = "2018" [dependencies] bincode = "1.3" -serde = { version = "1.0", features = ["derive"] } \ No newline at end of file +serde = { version = "1.0", features = ["derive"] } +vulkano = "0.19" \ No newline at end of file diff --git a/daemon/src/daemon.rs b/daemon/src/daemon.rs index 6116446..a73ac17 100644 --- a/daemon/src/daemon.rs +++ b/daemon/src/daemon.rs @@ -41,7 +41,7 @@ impl Daemon { let d = self.clone(); match stream { Ok(stream) => { - thread::spawn(move || Daemon::handle_connection(d, stream)); + thread::spawn(move || d.handle_connection(stream)); } Err(err) => { println!("Error: {}", err); @@ -54,7 +54,7 @@ impl Daemon { fn handle_connection(self, mut stream: UnixStream) { let mut buffer = Vec::::new(); stream.read_to_end(&mut buffer).unwrap(); - println!("finished reading"); + println!("finished reading, buffer size {}", buffer.len()); let action: Action = bincode::deserialize(&buffer).unwrap(); let response: Vec = match action { diff --git a/daemon/src/gpu_controller.rs b/daemon/src/gpu_controller.rs index e15ee77..582160b 100644 --- a/daemon/src/gpu_controller.rs +++ b/daemon/src/gpu_controller.rs @@ -1,5 +1,6 @@ use crate::fan_controller::FanController; use serde::{Deserialize, Serialize}; +use vulkano::instance::{Instance, InstanceExtensions, PhysicalDevice}; use std::fs; use std::path::PathBuf; @@ -10,44 +11,53 @@ pub struct GpuStats { } #[derive(Clone)] -pub struct GpuController { +pub struct GpuController { hw_path: PathBuf, fan_controller: FanController, pub gpu_info: GpuInfo, } +#[derive(Serialize, Deserialize, Debug, Clone, Default)] +pub struct VulkanInfo { + pub device_name: String, + pub api_version: String, + pub features: String, +} + #[derive(Serialize, Deserialize, Debug, Clone, Default)] pub struct GpuInfo { pub gpu_vendor: String, pub gpu_model: String, pub card_model: String, pub card_vendor: String, + pub model_id: String, + pub vendor_id: String, pub driver: String, pub vbios_version: String, pub vram_size: u64, //in MiB pub link_speed: String, pub link_width: u8, + pub vulkan_info: VulkanInfo, } impl GpuController { pub fn new(hw_path: &str) -> Self { - let gpu_info = GpuController::get_info(PathBuf::from(hw_path)); - println!("Initializing for {:?}", gpu_info); - - GpuController { + let mut controller = GpuController { hw_path: PathBuf::from(hw_path), fan_controller: FanController::new(hw_path), - gpu_info, - } + gpu_info: Default::default(), + }; + controller.gpu_info = controller.get_info(); + println!("{:?}", controller.gpu_info); + controller } - fn get_info(hw_path: PathBuf) -> GpuInfo { - let uevent = fs::read_to_string(hw_path.join("uevent")).expect("Failed to read uevent"); + fn get_info(&self) -> GpuInfo { + let uevent = fs::read_to_string(self.hw_path.join("uevent")).expect("Failed to read uevent"); - //caps for raw values, lowercase for parsed let mut driver = String::new(); - let mut VENDOR_ID = String::new(); - let mut MODEL_ID = String::new(); + let mut vendor_id = String::new(); + let mut model_id = String::new(); let mut CARD_VENDOR_ID = String::new(); let mut CARD_MODEL_ID = String::new(); @@ -57,8 +67,8 @@ impl GpuController { "DRIVER" => driver = split[1].to_string(), "PCI_ID" => { let ids = split[1].split(':').collect::>(); - VENDOR_ID = ids[0].to_string(); - MODEL_ID = ids[1].to_string(); + vendor_id = ids[0].to_string(); + model_id = ids[1].to_string(); } "PCI_SUBSYS_ID" => { let ids = split[1].split(':').collect::>(); @@ -78,7 +88,7 @@ impl GpuController { .expect("Could not read pci.ids. Perhaps the \"hwids\" package is not installed?"); //some weird space character, don't touch - let pci_id_line = format!(" {}", MODEL_ID.to_lowercase()); + let pci_id_line = format!(" {}", model_id.to_lowercase()); let card_ids_line = format!( " {} {}", CARD_VENDOR_ID.to_lowercase(), @@ -101,12 +111,12 @@ impl GpuController { } } - let vbios_version = fs::read_to_string(hw_path.join("vbios_version")) + let vbios_version = fs::read_to_string(self.hw_path.join("vbios_version")) .expect("Failed to read vbios_info") .trim() .to_string(); - let vram_size = fs::read_to_string(hw_path.join("mem_info_vram_total")) + let vram_size = fs::read_to_string(self.hw_path.join("mem_info_vram_total")) .expect("Failed to read mem size") .trim() .parse::() @@ -114,27 +124,32 @@ impl GpuController { / 1024 / 1024; - let link_speed = fs::read_to_string(hw_path.join("current_link_speed")) + let link_speed = fs::read_to_string(self.hw_path.join("current_link_speed")) .expect("Failed to read link speed") .trim() .to_string(); - let link_width = fs::read_to_string(hw_path.join("current_link_width")) + let link_width = fs::read_to_string(self.hw_path.join("current_link_width")) .expect("Failed to read link width") .trim() .parse::() .unwrap(); + let vulkan_info = GpuController::get_vulkan_info(&model_id); + GpuInfo { gpu_vendor: vendor, gpu_model: model, card_vendor, card_model, + model_id, + vendor_id, driver, vbios_version, vram_size, link_speed, link_width, + vulkan_info, } } @@ -159,4 +174,26 @@ impl GpuController { mem_used, } } + + fn get_vulkan_info(pci_id: &str) -> VulkanInfo { + let instance = Instance::new(None, &InstanceExtensions::none(), None) + .expect("failed to create instance"); + + for physical in PhysicalDevice::enumerate(&instance) { + if format!("{:x}", physical.pci_device_id()) == pci_id.to_lowercase() { + let api_version = physical.api_version().to_string(); + let device_name = physical.name().to_string(); + let features = format!("{:?}", physical.supported_features()); + + return VulkanInfo { + device_name, + api_version, + features, + }; + } + } + + VulkanInfo { device_name: "Not supported".to_string(), api_version: "".to_string(), features: "".to_string()} + + } } diff --git a/daemon/src/lib.rs b/daemon/src/lib.rs index da9bc42..e0b7f00 100644 --- a/daemon/src/lib.rs +++ b/daemon/src/lib.rs @@ -9,6 +9,7 @@ pub mod gpu_controller; pub const SOCK_PATH: &str = "/tmp/amdgpu-configurator.sock"; +#[derive(Debug)] pub enum DaemonError { ConnectionFailed, } @@ -43,4 +44,6 @@ pub fn get_gpu_info() -> Result { } Err(_) => Err(DaemonError::ConnectionFailed), } + + } diff --git a/gui/src/main.rs b/gui/src/main.rs index 8baf8c5..47b3ab6 100644 --- a/gui/src/main.rs +++ b/gui/src/main.rs @@ -41,6 +41,19 @@ fn build_ui(application: >k::Application) { .get_object("link_speed_text_buffer") .expect("Couldn't get textbuffer"); + let vulkan_device_name_text_buffer: TextBuffer = builder + .get_object("vulkan_device_name_text_buffer") + .expect("Couldn't get textbuffer"); + + let vulkan_version_text_buffer: TextBuffer = builder + .get_object("vulkan_version_text_buffer") + .expect("Couldn't get textbuffer"); + + let vulkan_features_text_buffer: TextBuffer = builder + .get_object("vulkan_features_text_buffer") + .expect("Couldn't get textbuffer"); + + match daemon::get_gpu_info() { Ok(gpu_info) => { gpu_model_text_buffer.set_text(&gpu_info.card_model); @@ -49,6 +62,10 @@ fn build_ui(application: >k::Application) { driver_text_buffer.set_text(&gpu_info.driver); vram_size_text_buffer.set_text(&format!("{} MiB", &gpu_info.vram_size)); link_speed_text_buffer.set_text(&format!("{} x{}", &gpu_info.link_speed, &gpu_info.link_width)); + + vulkan_device_name_text_buffer.set_text(&gpu_info.vulkan_info.device_name); + vulkan_version_text_buffer.set_text(&gpu_info.vulkan_info.api_version); + vulkan_features_text_buffer.set_text(&gpu_info.vulkan_info.features); } Err(_) => { MessageDialog::new( diff --git a/gui/src/main_window.glade b/gui/src/main_window.glade index 78cad3a..33060b0 100644 --- a/gui/src/main_window.glade +++ b/gui/src/main_window.glade @@ -20,6 +20,15 @@ 1024 MiB + + Vulkan Device + + + orage_image_extended_formats: true, shader_storage_image_multisample: true, shader_storage_image_read_without_format: true, shader_storage_image_write_without_format: true, shader_uniform_buffer_array_dynamic_indexing: true, shader_sampled_image_array_dynamic_indexing: true, shader_storage_buffer_array_dynamic_indexing: true, shader_storage_image_array_dynamic_indexing: true, shader_clip_distance: true, shader_cull_distance: true, shader_f3264: true, shader_int64: true, shader_int16: true, shader_resource_residency: false, shader_resource_min_lod: true, sparse_binding: true, sparse_residency_buffer: false, sparse_residency_image2d: false, sparse_residency_image3d: false, sparse_residency2_samples: false, sparse_residency4_samples: false, sparse_residency8_samples: false, sparse_residency16_samples: false, sparse_residency_aliased: false, variable_multisample_rate: true, inherited_queries: true, buffer_device_address: false, buffer_device_address_capture_replay: false, buffer_device_address_multi_device: false }" } } + + + 1.0.0 + False 350 @@ -29,7 +38,7 @@ True True - + True False @@ -251,6 +260,134 @@ 5 + + + True + False + 5 + 5 + 0.5 + none + + + + True + False + center + + + True + False + end + 5 + 5 + 5 + 5 + Device Name + fill + + + 0 + 0 + + + + + True + False + end + 5 + 5 + 5 + 5 + Version + + + 0 + 1 + + + + + True + True + 5 + 5 + vulkan_device_name_text_buffer + + + 1 + 0 + + + + + True + True + 5 + 5 + vulkan_version_text_buffer + + + 1 + 1 + + + + + True + True + True + True + + + True + True + in + True + + + True + True + word + vulkan_features_text_buffer + + + + + + + True + False + Feature support + + + + + 0 + 2 + 2 + + + + + + + True + False + Vulkan information + + + + + + + + 0 + 6 + 2 + + diff --git a/gui/src/main_window.glade~ b/gui/src/main_window.glade~ deleted file mode 100644 index 1b12d7c..0000000 --- a/gui/src/main_window.glade~ +++ /dev/null @@ -1,278 +0,0 @@ - - - - - - False - popup - center - True - dialog - True - error - Unable to connect to the service - - - False - vertical - 2 - - - False - True - end - - - - - - - - - False - False - 0 - - - - - - - driver - - - gpu_model - - - Manufacturer - - - vbios_version - - - False - 350 - 500 - - - True - True - - - - True - False - - - True - False - end - 5 - 5 - 5 - 5 - True - GPU Model - fill - - - 0 - 0 - - - - - True - True - WARNING: GPU model identification by PCI ID's may not be accurate. - 6 - True - False - fill - False - gpu_model_text_buffer - False - True - - - 1 - 0 - - - - - True - False - end - 5 - 5 - 5 - 5 - True - VBIOS Version - right - - - 0 - 2 - - - - - True - True - 7 - True - False - fill - False - vbios_version_text_buffer - False - True - - - 1 - 2 - - - - - True - False - end - 5 - 5 - 5 - 5 - True - Driver in use - fill - - - 0 - 3 - - - - - True - True - 7 - True - False - fill - False - driver_text_buffer - False - True - - - 1 - 3 - - - - - True - False - end - 5 - 5 - 5 - 5 - Manufacturer - fill - - - 0 - 1 - - - - - True - True - 7 - True - False - fill - False - manufacturer_text_buffer - False - True - - - 1 - 1 - - - - - - - True - False - Information - - - False - - - - - - True - False - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1 - - - - - True - False - page 2 - - - 1 - False - - - - - - - - - - - -