diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 5d3c4e0..489f7e3 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -64,11 +64,11 @@ checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" [[package]] name = "ash" -version = "0.38.0+1.3.281" +version = "0.37.3+1.3.251" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bb44936d800fea8f016d7f2311c6a4f97aebd5dc86f09906139ec848cf3a46f" +checksum = "39e9c3835d686b0a6084ab4234fcd1b07dbf6e4767dce60874b12356a25ecd4a" dependencies = [ - "libloading", + "libloading 0.7.4", ] [[package]] @@ -1490,6 +1490,16 @@ version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +[[package]] +name = "libloading" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" +dependencies = [ + "cfg-if", + "winapi", +] + [[package]] name = "libloading" version = "0.8.4" @@ -1772,7 +1782,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c9bff0aa1d48904a1385ea2a8b97576fbdcbc9a3cfccd0d31fe978e1c4038c5" dependencies = [ "bitflags 2.5.0", - "libloading", + "libloading 0.8.4", "nvml-wrapper-sys", "static_assertions", "thiserror", @@ -1785,7 +1795,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "698d45156f28781a4e79652b6ebe2eaa0589057d588d3aec1333f6466f13fcb5" dependencies = [ - "libloading", + "libloading 0.8.4", ] [[package]] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 6f0ecd9..3633f47 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -20,7 +20,7 @@ battery = "0.7.8" libmedium = "0.8.1" dirs = "5.0.1" nvml-wrapper = "0.10.0" -ash = "0.38.0" +ash = "0.37.3" [features] # This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!! diff --git a/src-tauri/src/gpu.rs b/src-tauri/src/gpu.rs index f0d0c38..25fbf03 100644 --- a/src-tauri/src/gpu.rs +++ b/src-tauri/src/gpu.rs @@ -1,12 +1,12 @@ -use ash::vk; -use ash::Entry; use serde::{Deserialize, Serialize}; use nvml_wrapper::Nvml; use nvml_wrapper::error::NvmlError; use std::error::Error; -use std::ffi::CStr; use std::fs::{read_dir, read_to_string}; use std::path::PathBuf; +use ash::vk; +use ash::Entry; +use std::ffi::CStr; use std::ptr; #[derive(Serialize, Deserialize, Debug)] @@ -114,10 +114,10 @@ fn read_hwmon_info( if let Ok(power_input) = read_to_string(hwmon_path.join("power1_average")) { let power_mw = power_input.trim().parse::().unwrap_or(0); - wattage = Some(format!("{:.3} W", power_mw as f64 / 1000.0)); // Divide by 1000 to convert mW to W + wattage = Some(format!("{:.3} W", power_mw as f64 / 1000000.0)); } else if let Ok(power_input) = read_to_string(hwmon_path.join("power1_input")) { let power_mw = power_input.trim().parse::().unwrap_or(0); - wattage = Some(format!("{:.3} W", power_mw as f64 / 1000.0)); // Divide by 1000 to convert mW to W + wattage = Some(format!("{:.3} W", power_mw as f64 / 1000000.0)); } } } @@ -126,6 +126,71 @@ fn read_hwmon_info( (fan_speed, temperature, clock_speed, wattage) } +fn get_amd_gpu_name() -> String { + // Initialize Vulkan entry point + let entry = unsafe { Entry::load().expect("Failed to create Vulkan entry") }; + + // Create a Vulkan instance + let app_name = CStr::from_bytes_with_nul(b"AMD GPU Detector\0").unwrap(); + let engine_name = CStr::from_bytes_with_nul(b"No Engine\0").unwrap(); + + let app_info = vk::ApplicationInfo { + s_type: vk::StructureType::APPLICATION_INFO, + p_next: ptr::null(), + p_application_name: app_name.as_ptr(), + p_engine_name: engine_name.as_ptr(), + application_version: vk::make_api_version(0, 1, 0, 0), + engine_version: vk::make_api_version(0, 1, 0, 0), + api_version: vk::make_api_version(0, 1, 0, 0), + }; + + let create_info = vk::InstanceCreateInfo { + s_type: vk::StructureType::INSTANCE_CREATE_INFO, + p_next: ptr::null(), + flags: vk::InstanceCreateFlags::empty(), + p_application_info: &app_info, + enabled_layer_count: 0, + pp_enabled_layer_names: ptr::null(), + enabled_extension_count: 0, + pp_enabled_extension_names: ptr::null(), + }; + + let instance = unsafe { + entry + .create_instance(&create_info, None) + .expect("Failed to create Vulkan instance") + }; + + // Enumerate physical devices (GPUs) + let physical_devices = unsafe { + instance + .enumerate_physical_devices() + .expect("Failed to enumerate physical devices") + }; + + // Get the name of the first GPU + let device_name = if let Some(&device) = physical_devices.first() { + // Get device properties + let properties = unsafe { instance.get_physical_device_properties(device) }; + + // Convert the device name to a Rust String + unsafe { + CStr::from_ptr(properties.device_name.as_ptr()) + .to_string_lossy() + .into_owned() + } + } else { + String::from("No GPU found") + }; + + // Clean up Vulkan instance + unsafe { + instance.destroy_instance(None); + } + + device_name +} + fn get_amd_gpu_info() -> Result> { let drm_path = PathBuf::from("/sys/class/drm/"); let mut amd_gpu_path = None; @@ -184,7 +249,7 @@ fn get_amd_gpu_info() -> Result> { let utilization = read_gpu_busy_percent(&device_path); Ok(GpuInformations { - name: Some("AMD GPU".to_string()), + name: Some(get_amd_gpu_name()), driver_version: None, memory_total, memory_used,