diff --git a/Cargo.lock b/Cargo.lock index 13e3b20c8..3632e9901 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1156,6 +1156,15 @@ dependencies = [ "url", ] +[[package]] +name = "humansize" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e682e2bd70ecbcce5209f11a992a4ba001fea8e60acf7860ce007629e6d2756" +dependencies = [ + "libm", +] + [[package]] name = "humantime" version = "2.1.0" @@ -1293,6 +1302,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "libm" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb" + [[package]] name = "libnghttp2-sys" version = "0.1.7+1.45.0" @@ -2762,6 +2777,7 @@ dependencies = [ "easy-ext", "flate2", "heck", + "humansize", "once_cell", "onnxruntime", "open_jtalk", @@ -2773,6 +2789,8 @@ dependencies = [ "surf", "tar", "thiserror", + "tracing", + "windows", ] [[package]] @@ -2969,49 +2987,106 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.43.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04662ed0e3e5630dfa9b26e4cb823b817f1a9addda855d973a9458c236556244" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc 0.42.0", + "windows_i686_gnu 0.42.0", + "windows_i686_msvc 0.42.0", + "windows_x86_64_gnu 0.42.0", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc 0.42.0", +] + [[package]] name = "windows-sys" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" dependencies = [ - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_msvc", + "windows_aarch64_msvc 0.36.1", + "windows_i686_gnu 0.36.1", + "windows_i686_msvc 0.36.1", + "windows_x86_64_gnu 0.36.1", + "windows_x86_64_msvc 0.36.1", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" + [[package]] name = "windows_aarch64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" + [[package]] name = "windows_i686_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" +[[package]] +name = "windows_i686_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" + [[package]] name = "windows_i686_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" +[[package]] +name = "windows_i686_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" + [[package]] name = "windows_x86_64_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" + [[package]] name = "windows_x86_64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" + [[package]] name = "xattr" version = "0.2.3" diff --git a/Cargo.toml b/Cargo.toml index c3a158a0a..222cbeb96 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ once_cell = "1.15.0" serde = { version = "1.0.145", features = ["derive"] } serde_json = "1.0.85" thiserror = "1.0.37" +tracing = { version = "0.1.37", features = ["log"] } voicevox_core = { path = "crates/voicevox_core" } # min-sized-rustを元にrelease buildのサイズが小さくなるようにした diff --git a/crates/voicevox_core/Cargo.toml b/crates/voicevox_core/Cargo.toml index 6f64dc284..248c6a7d4 100644 --- a/crates/voicevox_core/Cargo.toml +++ b/crates/voicevox_core/Cargo.toml @@ -31,3 +31,8 @@ surf = "2.3.2" flate2 = "1.0.24" tar = "0.4.38" heck = "0.4.0" + +[target."cfg(windows)".dependencies] +humansize = "2.1.2" +tracing.workspace = true +windows = { version = "0.43.0", features = ["Win32_Foundation", "Win32_Graphics_Dxgi"] } diff --git a/crates/voicevox_core/src/publish.rs b/crates/voicevox_core/src/publish.rs index d4e9ee152..304772e51 100644 --- a/crates/voicevox_core/src/publish.rs +++ b/crates/voicevox_core/src/publish.rs @@ -33,6 +33,9 @@ impl VoicevoxCore { } fn new() -> Self { + #[cfg(windows)] + list_windows_video_cards(); + Self { synthesis_engine: SynthesisEngine::new( InferenceCore::new(false, None), @@ -607,6 +610,44 @@ pub const fn error_result_to_message(result_code: VoicevoxResultCode) -> &'stati } } +#[cfg(windows)] +fn list_windows_video_cards() { + use std::{ffi::OsString, os::windows::ffi::OsStringExt as _}; + + use humansize::BINARY; + use tracing::{error, info}; + use windows::Win32::Graphics::Dxgi::{ + CreateDXGIFactory, IDXGIFactory, DXGI_ADAPTER_DESC, DXGI_ERROR_NOT_FOUND, + }; + + info!("検出されたGPU (DirectMLには1番目のGPUが使われます):"); + match list_windows_video_cards() { + Ok(descs) => { + for desc in descs { + let description = OsString::from_wide(trim_nul(&desc.Description)); + let vram = humansize::format_size(desc.DedicatedVideoMemory, BINARY); + info!(" - {description:?} ({vram})"); + } + } + Err(err) => error!("{err}"), + } + + fn list_windows_video_cards() -> windows::core::Result> { + #[allow(unsafe_code)] + unsafe { + let factory = CreateDXGIFactory::()?; + (0..) + .map(|i| factory.EnumAdapters(i)?.GetDesc()) + .take_while(|r| !matches!(r, Err(e) if e.code() == DXGI_ERROR_NOT_FOUND)) + .collect() + } + } + + fn trim_nul(s: &[u16]) -> &[u16] { + &s[..s.iter().position(|&c| c == 0x0000).unwrap_or(s.len())] + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/crates/voicevox_core_python_api/Cargo.toml b/crates/voicevox_core_python_api/Cargo.toml index f8b35a3cb..04b33a192 100644 --- a/crates/voicevox_core_python_api/Cargo.toml +++ b/crates/voicevox_core_python_api/Cargo.toml @@ -22,5 +22,5 @@ pyo3 = { version = "0.17.2", features = ["abi3-py38", "extension-module"] } pyo3-log = "0.7.0" serde.workspace = true serde_json.workspace = true -tracing = { version = "0.1.37", features = ["log"] } +tracing.workspace = true voicevox_core.workspace = true