Make iced_wgpu build on redox
This commit is contained in:
parent
08fe1f3aa5
commit
64ef6b2724
3 changed files with 56 additions and 71 deletions
|
|
@ -47,7 +47,8 @@ lyon.optional = true
|
||||||
resvg.workspace = true
|
resvg.workspace = true
|
||||||
resvg.optional = 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" }
|
rustix = { version = "0.38" }
|
||||||
raw-window-handle.workspace = true
|
raw-window-handle.workspace = true
|
||||||
sctk.workspace = true
|
sctk.workspace = true
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,19 @@
|
||||||
//! Display rendering results on windows.
|
//! Display rendering results on windows.
|
||||||
pub mod compositor;
|
pub mod compositor;
|
||||||
#[cfg(all(unix, not(target_os = "macos")))]
|
#[cfg(all(unix, not(target_os = "macos"), not(target_os = "redox")))]
|
||||||
mod wayland;
|
mod wayland;
|
||||||
#[cfg(all(unix, not(target_os = "macos")))]
|
#[cfg(all(unix, not(target_os = "macos"), not(target_os = "redox")))]
|
||||||
mod x11;
|
mod x11;
|
||||||
|
|
||||||
pub use compositor::Compositor;
|
pub use compositor::Compositor;
|
||||||
pub use wgpu::Surface;
|
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};
|
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};
|
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)> {
|
fn ids_from_dev(dev: u64) -> Option<(u16, u16)> {
|
||||||
let path = PathBuf::from(format!(
|
let path = PathBuf::from(format!(
|
||||||
"/sys/dev/char/{}:{}/device",
|
"/sys/dev/char/{}:{}/device",
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,9 @@ use crate::graphics::{self, Shell, Viewport};
|
||||||
use crate::settings::{self, Settings};
|
use crate::settings::{self, Settings};
|
||||||
use crate::{Engine, Renderer};
|
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;
|
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 super::x11::get_x11_device_ids;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
|
|
||||||
|
|
@ -58,7 +58,7 @@ impl Compositor {
|
||||||
compatible_window: Option<W>,
|
compatible_window: Option<W>,
|
||||||
shell: Shell,
|
shell: Shell,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
#[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| {
|
let ids = compatible_window.as_ref().and_then(|window| {
|
||||||
get_wayland_device_ids(window)
|
get_wayland_device_ids(window)
|
||||||
.or_else(|| get_x11_device_ids(window))
|
.or_else(|| get_x11_device_ids(window))
|
||||||
|
|
@ -69,7 +69,7 @@ impl Compositor {
|
||||||
// 2. and nobody set an adapter name,
|
// 2. and nobody set an adapter name,
|
||||||
// 3. and the user didn't request the high power pref
|
// 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
|
// => 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, _)))
|
if !matches!(ids, Some((0x10de, _)))
|
||||||
&& std::env::var_os("WGPU_ADAPTER_NAME").is_none()
|
&& std::env::var_os("WGPU_ADAPTER_NAME").is_none()
|
||||||
&& std::env::var("WGPU_POWER_PREF").as_deref() != Ok("high")
|
&& std::env::var("WGPU_POWER_PREF").as_deref() != Ok("high")
|
||||||
|
|
@ -121,68 +121,52 @@ impl Compositor {
|
||||||
compatible_surface: compatible_surface.as_ref(),
|
compatible_surface: compatible_surface.as_ref(),
|
||||||
force_fallback_adapter: false,
|
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 =
|
let adapter = match adapter {
|
||||||
instance.request_adapter(&adapter_options).await.map_err(
|
Some(adapter) => adapter,
|
||||||
|_error| Error::NoAdapterFound(format!("{adapter_options:?}")),
|
None => instance.request_adapter(&adapter_options).await.map_err(
|
||||||
)?;
|
|_| 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?
|
|
||||||
log::info!("Selected: {:#?}", adapter.get_info());
|
log::info!("Selected: {:#?}", adapter.get_info());
|
||||||
|
|
||||||
let (format, alpha_mode) = compatible_surface
|
let (format, alpha_mode) = compatible_surface
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue