Files
proton-stream/crates/pstr-app/build.rs
nvrl 6ccc0c5e69 fix(app): run on the discrete GPU and buffer 4K on Windows
4K HEVC 10-bit stuttered on a Windows laptop with an RTX 3050 (B66).

- proton-stream.exe exports NvOptimusEnablement and
  AmdPowerXpressRequestHighPerformance, through a .def file build.rs
  hands the linker, so hybrid-graphics drivers start it on the discrete
  GPU instead of the iGPU that owned the GL context mpv renders into.
- The desktop mpv buffer ceiling is 256 MiB instead of 48 MiB, about
  five seconds of a 4K remux. Safe above the block ring because the app
  runs block read-ahead at 0 (B8). Android keeps 48 MiB.
2026-11-22 16:36:49 +01:00

37 lines
1.5 KiB
Rust

//! Compiles `proton-stream.rc` into the Windows exe; nothing on any other
//! target. `rc.exe` on an MSVC build, mingw's `windres` on the cross build
//! from Linux.
fn main() {
println!("cargo:rerun-if-changed=proton-stream.rc");
println!("cargo:rerun-if-changed=../../packaging/windows/proton-stream.ico");
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows") {
return;
}
export_gpu_preference();
// Only the GUI gets the icon; `pstr` is a console tool.
embed_resource::compile_for("proton-stream.rc", ["proton-stream"], embed_resource::NONE)
.manifest_optional()
.expect("compile the icon resource");
}
/// Export `NvOptimusEnablement` and `AmdPowerXpressRequestHighPerformance`
/// from `proton-stream.exe` (see `src/main.rs`). An executable exports nothing
/// by default, so the symbols go through a module-definition file: `link.exe`
/// takes it as `/DEF:`, and GNU ld for PE takes a `.def` as a plain input.
fn export_gpu_preference() {
let out = std::path::PathBuf::from(std::env::var("OUT_DIR").expect("OUT_DIR"));
let def = out.join("proton-stream-exports.def");
std::fs::write(
&def,
"EXPORTS\n NvOptimusEnablement DATA\n AmdPowerXpressRequestHighPerformance DATA\n",
)
.expect("write the exports .def");
let arg = if std::env::var("CARGO_CFG_TARGET_ENV").as_deref() == Ok("msvc") {
format!("/DEF:{}", def.display())
} else {
def.display().to_string()
};
println!("cargo:rustc-link-arg-bin=proton-stream={arg}");
}