Skip to content

Commit

Permalink
fix(wgpu): invisible windows on X11 desktops with dGPU+iGPU
Browse files Browse the repository at this point in the history
  • Loading branch information
mmstick committed Jul 6, 2024
1 parent 6f83a8d commit f6ba094
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions wgpu/src/window/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ impl Compositor {
let compatible_surface = compatible_window
.and_then(|window| instance.create_surface(window).ok());

let mut set_wgpu_power_pref = false;
let mut adapter = None;
#[cfg_attr(not(unix), allow(dead_code))]
if std::env::var_os("WGPU_ADAPTER_NAME").is_none() {
Expand All @@ -88,6 +89,23 @@ impl Compositor {
true
}
});
} else if std::env::var("XDG_SESSION_TYPE") == "x11" {

Check failure on line 92 in wgpu/src/window/compositor.rs

View workflow job for this annotation

GitHub Actions / all

mismatched types

Check failure on line 92 in wgpu/src/window/compositor.rs

View workflow job for this annotation

GitHub Actions / all

mismatched types
set_wgpu_power_pref = true;
fn is_desktop() -> bool {
let chassis = std::fs::read_to_string(
"/sys/class/dmi/id/chassis_type",
)
.unwrap_or_default();

chassis.trim() == "3"
}

// Fixes X11 desktops displaying an invisible window when a dGPU is used, but an iGPU is present.
// Prefers using an iGPU on X11 laptops that containa dGPU.
std::env::set_var(
"WGPU_POWER_PREF",
if is_desktop() { "high" } else { "low" },
);
}
} else if let Ok(name) = std::env::var("WGPU_ADAPTER_NAME") {
adapter = available_adapters
Expand Down Expand Up @@ -126,6 +144,10 @@ impl Compositor {

log::info!("Selected: {:#?}", adapter.get_info());

if set_wgpu_power_pref {
std::env::remove_var("WGPU_POWER_PREF");
}

let format = compatible_surface.as_ref().and_then(|surface| {
let capabilities = surface.get_capabilities(&adapter);

Expand Down

0 comments on commit f6ba094

Please sign in to comment.