diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 7118fb2e..0bd8a78d 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -47,7 +47,8 @@ lyon.optional = true resvg.workspace = true resvg.optional = true -[target.'cfg(all(unix, not(target_os = "macos")))'.dependencies] +[target.'cfg(all(unix, not(target_os = "macos"), not(target_os = "redox")))'.dependencies] + rustix = { version = "0.38" } raw-window-handle.workspace = true sctk.workspace = true diff --git a/wgpu/src/window.rs b/wgpu/src/window.rs index 92f16873..011f60e5 100644 --- a/wgpu/src/window.rs +++ b/wgpu/src/window.rs @@ -1,19 +1,19 @@ //! Display rendering results on windows. pub mod compositor; -#[cfg(all(unix, not(target_os = "macos")))] +#[cfg(all(unix, not(target_os = "macos"), not(target_os = "redox")))] mod wayland; -#[cfg(all(unix, not(target_os = "macos")))] +#[cfg(all(unix, not(target_os = "macos"), not(target_os = "redox")))] mod x11; pub use compositor::Compositor; pub use wgpu::Surface; -#[cfg(all(unix, not(target_os = "macos")))] +#[cfg(all(unix, not(target_os = "macos"), not(target_os = "redox")))] use rustix::fs::{major, minor}; -#[cfg(all(unix, not(target_os = "macos")))] +#[cfg(all(unix, not(target_os = "macos"), not(target_os = "redox")))] use std::{fs::File, io::Read, path::PathBuf}; -#[cfg(all(unix, not(target_os = "macos")))] +#[cfg(all(unix, not(target_os = "macos"), not(target_os = "redox")))] fn ids_from_dev(dev: u64) -> Option<(u16, u16)> { let path = PathBuf::from(format!( "/sys/dev/char/{}:{}/device", diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index 7ec93e18..27f9a4da 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -7,9 +7,9 @@ use crate::graphics::{self, Shell, Viewport}; use crate::settings::{self, Settings}; use crate::{Engine, Renderer}; -#[cfg(all(unix, not(target_os = "macos")))] +#[cfg(all(unix, not(target_os = "macos"), not(target_os = "redox")))] use super::wayland::get_wayland_device_ids; -#[cfg(all(unix, not(target_os = "macos")))] +#[cfg(all(unix, not(target_os = "macos"), not(target_os = "redox")))] use super::x11::get_x11_device_ids; use std::future::Future; @@ -58,7 +58,7 @@ impl Compositor { compatible_window: Option, shell: Shell, ) -> Result { - #[cfg(all(unix, not(target_os = "macos")))] + #[cfg(all(unix, not(target_os = "macos"), not(target_os = "redox")))] let ids = compatible_window.as_ref().and_then(|window| { get_wayland_device_ids(window) .or_else(|| get_x11_device_ids(window)) @@ -69,7 +69,7 @@ impl Compositor { // 2. and nobody set an adapter name, // 3. and the user didn't request the high power pref // => don't load the nvidia icd, as it might power on the gpu in hybrid setups causing severe delays - #[cfg(all(unix, not(target_os = "macos")))] + #[cfg(all(unix, not(target_os = "macos"), not(target_os = "redox")))] if !matches!(ids, Some((0x10de, _))) && std::env::var_os("WGPU_ADAPTER_NAME").is_none() && std::env::var("WGPU_POWER_PREF").as_deref() != Ok("high") @@ -121,68 +121,52 @@ impl Compositor { compatible_surface: compatible_surface.as_ref(), force_fallback_adapter: false, }; + let mut adapter = None; + #[cfg_attr(not(unix), allow(dead_code))] + if std::env::var_os("WGPU_ADAPTER_NAME").is_none() { + #[cfg(all( + unix, + not(target_os = "macos"), + not(target_os = "redox") + ))] + if let Some((vendor_id, device_id)) = ids { + adapter = available_adapters + .into_iter() + .filter(|adapter| { + let info = adapter.get_info(); + info.device == device_id as u32 + && info.vendor == vendor_id as u32 + }) + .find(|adapter| { + if let Some(surface) = compatible_surface.as_ref() { + adapter.is_surface_supported(surface) + } else { + true + } + }); + } + } else if let Ok(name) = std::env::var("WGPU_ADAPTER_NAME") { + adapter = available_adapters + .into_iter() + .filter(|adapter| { + let info = adapter.get_info(); + info.name == name + }) + .find(|adapter| { + if let Some(surface) = compatible_surface.as_ref() { + adapter.is_surface_supported(surface) + } else { + true + } + }); + } - let adapter = - instance.request_adapter(&adapter_options).await.map_err( - |_error| Error::NoAdapterFound(format!("{adapter_options:?}")), - )?; - // start pop - // let mut adapter = None; - // #[cfg_attr(not(unix), allow(dead_code))] - // if std::env::var_os("WGPU_ADAPTER_NAME").is_none() { - // #[cfg(all(unix, not(target_os = "macos")))] - // if let Some((vendor_id, device_id)) = ids { - // adapter = available_adapters - // .into_iter() - // .filter(|adapter| { - // let info = adapter.get_info(); - // info.device == device_id as u32 - // && info.vendor == vendor_id as u32 - // }) - // .find(|adapter| { - // if let Some(surface) = compatible_surface.as_ref() { - // adapter.is_surface_supported(surface) - // } else { - // true - // } - // }); - // } - // } else if let Ok(name) = std::env::var("WGPU_ADAPTER_NAME") { - // adapter = available_adapters - // .into_iter() - // .filter(|adapter| { - // let info = adapter.get_info(); - // info.name == name - // }) - // .find(|adapter| { - // if let Some(surface) = compatible_surface.as_ref() { - // adapter.is_surface_supported(surface) - // } else { - // true - // } - // }); - // } - - // let adapter = - // match adapter { - // Some(adapter) => adapter, - // None => instance - // .request_adapter(&wgpu::RequestAdapterOptions { - // power_preference: - // wgpu::util::power_preference_from_env().unwrap_or( - // if settings.antialiasing.is_none() { - // wgpu::PowerPreference::LowPower - // } else { - // wgpu::PowerPreference::HighPerformance - // }, - // ), - // compatible_surface: compatible_surface.as_ref(), - // force_fallback_adapter: false, - // }) - // .await?, - // }; - // end pop - // TODO(POP): Merge conflict ensued with above stuff, is your code still needed? + let adapter = match adapter { + Some(adapter) => adapter, + None => instance.request_adapter(&adapter_options).await.map_err( + |_| Error::NoAdapterFound(format!("{:?}", adapter_options)), + )?, + }; log::info!("Selected: {:#?}", adapter.get_info()); let (format, alpha_mode) = compatible_surface