Skip to content

Commit

Permalink
Merge pull request #23 from shm11C3/feature/amd-gpu-info
Browse files Browse the repository at this point in the history
Intel / AMD GPU 情報取得処理の追加
  • Loading branch information
shm11C3 authored Nov 10, 2024
2 parents f88253f + ebd9087 commit d5ab7c0
Show file tree
Hide file tree
Showing 14 changed files with 562 additions and 221 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"editor.formatOnSave": true,
"editor.inlayHints.enabled": "off"
},
"cSpell.words": ["consts", "nvapi", "tauri"],
"cSpell.words": ["consts", "directx", "nvapi", "tauri"],
"tailwindCSS.experimental.classRegex": [
"tv\\(([^)(]*(?:\\([^)(]*(?:\\([^)(]*(?:\\([^)(]*\\)[^)(]*)*\\)[^)(]*)*\\)[^)(]*)*)\\)"
]
Expand Down
146 changes: 142 additions & 4 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ tauri-plugin-dialog = "2.0.3"
tauri-plugin-store = "2.1.0"
base64 = "0.22"
image = "0.25.4"
dxgi = "0.1.7"
winapi = { version = "0.3", features = ["dxgi"] }
regex = "1.11.1"

[dependencies.uuid]
version = "1.11.0"
Expand All @@ -65,6 +68,9 @@ features = [
"Win32_Security",
"Win32_System_Threading",
"Win32_UI_WindowsAndMessaging",
#"Win32_Graphics_Direct3D",
#"Win32_Graphics_Direct3D11",
#"Win32_Graphics_Dxgi"
]

[lib]
Expand Down
62 changes: 50 additions & 12 deletions src-tauri/src/commands/hardware.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::services::graphic_service;
use crate::services::directx_gpu_service;
use crate::services::nvidia_gpu_service;
use crate::services::system_info_service;
use crate::services::wmi_service;
use crate::structs::hardware::{GraphicInfo, MemoryInfo};
use crate::{log_debug, log_error, log_info, log_internal, log_warn};
use serde::{Serialize, Serializer};
use std::collections::HashMap;
Expand Down Expand Up @@ -121,8 +124,8 @@ pub fn get_cpu_usage(state: tauri::State<'_, AppState>) -> i32 {
#[serde(rename_all = "camelCase")]
pub struct SysInfo {
pub cpu: Option<system_info_service::CpuInfo>,
pub memory: Option<system_info_service::MemoryInfo>,
pub gpus: Option<Vec<graphic_service::GraphicInfo>>,
pub memory: Option<MemoryInfo>,
pub gpus: Option<Vec<GraphicInfo>>,
}

///
Expand All @@ -133,13 +136,39 @@ pub async fn get_hardware_info(
state: tauri::State<'_, AppState>,
) -> Result<SysInfo, String> {
let cpu_result = system_info_service::get_cpu_info(state.system.lock().unwrap());
let memory_result = system_info_service::get_memory_info();
let gpus_result = graphic_service::get_nvidia_gpu_info().await;
let memory_result = wmi_service::get_memory_info();
let nvidia_gpus_result = nvidia_gpu_service::get_nvidia_gpu_info().await;
let amd_gpus_result = directx_gpu_service::get_amd_gpu_info().await;
let intel_gpus_result = directx_gpu_service::get_intel_gpu_info().await;

let mut gpus_result = Vec::new();

// NVIDIA の結果を確認して結合
match nvidia_gpus_result {
Ok(nvidia_gpus) => gpus_result.extend(nvidia_gpus),
Err(e) => log_error!("nvidia_error", "get_all_gpu_info", Some(e)),
}

// AMD の結果を確認して結合
match amd_gpus_result {
Ok(amd_gpus) => gpus_result.extend(amd_gpus),
Err(e) => log_error!("amd_error", "get_all_gpu_info", Some(e)),
}

// Intel の結果を確認して結合
match intel_gpus_result {
Ok(intel_gpus) => gpus_result.extend(intel_gpus),
Err(e) => log_error!("intel_error", "get_all_gpu_info", Some(e)),
}

let sys_info = SysInfo {
cpu: cpu_result.ok(),
memory: memory_result.ok(),
gpus: gpus_result.ok(),
gpus: if gpus_result.is_empty() {
None
} else {
Some(gpus_result)
},
};

// すべての情報が失敗した場合にのみエラーメッセージを返す
Expand Down Expand Up @@ -173,18 +202,26 @@ pub fn get_memory_usage(state: tauri::State<'_, AppState>) -> i32 {
///
#[command]
pub async fn get_gpu_usage() -> Result<i32, String> {
match graphic_service::get_nvidia_gpu_usage().await {
if let Ok(usage) = nvidia_gpu_service::get_nvidia_gpu_usage().await {
return Ok((usage * 100.0).round() as i32);
}

// NVIDIA APIが失敗した場合、WMIから取得を試みる
match wmi_service::get_gpu_usage_by_device_and_engine("3D").await {
Ok(usage) => Ok((usage * 100.0).round() as i32),
Err(e) => Err(format!("Failed to get GPU usage: {:?}", e)),
Err(e) => Err(format!(
"Failed to get GPU usage from both NVIDIA API and WMI: {:?}",
e
)),
}
}

///
/// ## GPU温度を取得
///
#[command]
pub async fn get_gpu_temperature() -> Result<Vec<graphic_service::NameValue>, String> {
match graphic_service::get_nvidia_gpu_temperature().await {
pub async fn get_gpu_temperature() -> Result<Vec<nvidia_gpu_service::NameValue>, String> {
match nvidia_gpu_service::get_nvidia_gpu_temperature().await {
Ok(temps) => Ok(temps),
Err(e) => Err(format!("Failed to get GPU temperature: {:?}", e)),
}
Expand All @@ -194,8 +231,9 @@ pub async fn get_gpu_temperature() -> Result<Vec<graphic_service::NameValue>, St
/// ## GPUのファン回転数を取得
///
#[command]
pub async fn get_nvidia_gpu_cooler() -> Result<Vec<graphic_service::NameValue>, String> {
match graphic_service::get_nvidia_gpu_cooler_stat().await {
pub async fn get_nvidia_gpu_cooler() -> Result<Vec<nvidia_gpu_service::NameValue>, String>
{
match nvidia_gpu_service::get_nvidia_gpu_cooler_stat().await {
Ok(temps) => Ok(temps),
Err(e) => Err(format!("Failed to get GPU cooler status: {:?}", e)),
}
Expand Down
Loading

0 comments on commit d5ab7c0

Please sign in to comment.