feat(src/commands): add run_on_dgpu command to launch applications on discrete GPU

Running applications on the dGPU now requires proper environment variable setup and runtime mode checking. The implementation includes warnings when the system is not in hybrid mode and logs the launched command and its exit status.

- New Feature: Implemented `run_on_dgpu` function to execute commands with NVIDIA offload environment variables.
- Enhancement: Added runtime mode verification and warning for non‑hybrid configurations.
- Enhancement: Added informational logging for launched command and process exit status.
This commit is contained in:
sankalp committed 2026-03-19 20:55:18 +05:45
1 parent 707192903e
commit 5e921d2833
1 file changed
+38
+38
View File
@@ -485,6 +485,43 @@ fn switch_nvidia(
println!("Please reboot your computer for changes to take effect!"); println!("Please reboot your computer for changes to take effect!");
} }
fn run_on_dgpu(command: &[String]) {
if command.is_empty() {
error!("No command provided to run.");
return;
}
if get_current_mode() != "hybrid" {
log::warn!(
"Running on dGPU is typically only effective in Hybrid mode. \
Your current mode is '{}'. The application may fail to start or \
not use the NVIDIA GPU.",
get_current_mode()
);
}
log::info!("Launching '{}' on the discrete GPU...", command.join(" "));
let mut child = Command::new(&command[0]);
if command.len() > 1 {
child.args(&command[1..]);
}
// Set PRIME offload variables natively
child.env("__NV_PRIME_RENDER_OFFLOAD", "1");
child.env("__GLX_VENDOR_LIBRARY_NAME", "nvidia");
child.env("__VK_LAYER_NV_optimus", "NVIDIA_only");
match child.status() {
Ok(status) => {
log::info!("Application exited with: {}", status);
}
Err(e) => {
error!("Failed to launch application: {}", e);
}
}
}
pub fn execute(cmd: &GpuCommands) { pub fn execute(cmd: &GpuCommands) {
match cmd { match cmd {
GpuCommands::Query => { GpuCommands::Query => {
@@ -551,5 +588,6 @@ pub fn execute(cmd: &GpuCommands) {
*use_nvidia_current, *use_nvidia_current,
*wayland, *wayland,
), ),
GpuCommands::Run { command } => run_on_dgpu(command),
} }
} }