-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: set gpu preference to high performance on windows by default
- Loading branch information
1 parent
cc86264
commit c7a5ac8
Showing
4 changed files
with
35 additions
and
2 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use eyre::ContextCompat; | ||
use eyre::Result; | ||
use std::env; | ||
use winreg::enums::*; | ||
use winreg::RegKey; | ||
|
||
pub fn set_gpu_preference() -> Result<()> { | ||
let hkcu = RegKey::predef(HKEY_CURRENT_USER); | ||
let directx = hkcu.open_subkey_with_flags("Software\\Microsoft\\DirectX", KEY_ALL_ACCESS)?; | ||
|
||
// Create the main key for the UserGpuPreferences if it doesn't exist | ||
let user_gpu_preferences = directx.create_subkey("UserGpuPreferences")?; | ||
|
||
// Get the current executable path | ||
let program_path = env::current_exe()?; | ||
let program_path_str = program_path.to_str().context("Failed to convert program path to string")?; | ||
|
||
// Set the GPU preference for the current executable | ||
// 0 = Auto ; 1 = Power Saving ; 2 = High | ||
user_gpu_preferences.0.set_value(program_path_str, &"GpuPreference=2;")?; | ||
|
||
log::debug!( | ||
"GPU preference set for high performance successfully for the current executable ({}).", | ||
program_path_str | ||
); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters