Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wgpu): invisible windows on X11 desktops with dGPU+iGPU #157

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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 @@

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
Loading