Skip to content

Commit

Permalink
Make iced_wgpu build on redox
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpot51 committed Oct 10, 2024
1 parent b645eca commit f482673
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ resvg.optional = true
tracing.workspace = true
tracing.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
Expand All @@ -53,4 +53,4 @@ wayland-client = { version = "0.31.2" }
wayland-sys = { version = "0.31.1", features = ["dlopen"] }
as-raw-xcb-connection = "1.0.1"
tiny-xlib = "0.2.3"
x11rb = { version = "0.13.1", features = ["allow-unsafe-code", "dl-libxcb", "dri3", "randr"] }
x11rb = { version = "0.13.1", features = ["allow-unsafe-code", "dl-libxcb", "dri3", "randr"] }
10 changes: 5 additions & 5 deletions wgpu/src/window.rs
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
14 changes: 9 additions & 5 deletions wgpu/src/window/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use crate::graphics::compositor;
use crate::graphics::{Error, Viewport};
use crate::{Backend, Primitive, Renderer, Settings};

#[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;

/// A window graphics backend for iced powered by `wgpu`.
Expand All @@ -30,7 +30,7 @@ impl Compositor {
settings: Settings,
compatible_window: Option<W>,
) -> Option<Self> {
#[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))
Expand All @@ -41,7 +41,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")
Expand Down Expand Up @@ -77,7 +77,11 @@ impl Compositor {
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")))]
#[cfg(all(
unix,
not(target_os = "macos"),
not(target_os = "redox")
))]
if let Some((vendor_id, device_id)) = ids {
adapter = available_adapters
.into_iter()
Expand Down

0 comments on commit f482673

Please sign in to comment.