Skip to content

Fix OpenBSD compilation of wgpu_hal::vulkan::drm #7810

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

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ Bottom level categories:

- Get `vertex_index` & `instance_index` builtins working for indirect draws. By @teoxoy in [#7535](https://github.com/gfx-rs/wgpu/pull/7535)

#### Vulkan

- Fix OpenBSD compilation of `wgpu_hal::vulkan::drm`. By @ErichDonGubler in [#7810](https://github.com/gfx-rs/wgpu/pull/7810).

#### Metal

- Remove extraneous main thread warning in `fn surface_capabilities()`. By @jamesordner in [#7692](https://github.com/gfx-rs/wgpu/pull/7692)
Expand Down
1 change: 1 addition & 0 deletions wgpu-core/platform-deps/apple/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ readme = "README.md"
rust-version = "1.76"

[features]
default = ["metal", "vulkan-portability"]
metal = ["wgpu-hal/metal"]
angle = ["wgpu-hal/gles", "wgpu-hal/renderdoc"]
vulkan-portability = ["wgpu-hal/vulkan", "wgpu-hal/renderdoc"]
Expand Down
23 changes: 19 additions & 4 deletions wgpu-hal/src/vulkan/drm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ use core::mem::MaybeUninit;

use ash::{ext, khr, vk};

macro_rules! to_u64 {
($expr:expr) => {{
#[allow(trivial_numeric_casts)]
let expr = $expr as u64;
assert!(size_of_val(&expr) <= size_of::<u64>());
expr
}};
}
Comment on lines +8 to +15
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to take this opportunity to express my distaste for the lack of portability motivating this workaround, and the workaround itself. 😫

Otherwise, thanks in advance for reviewing~!


impl super::Instance {
/// Creates a new surface from the given drm configuration.
///
Expand Down Expand Up @@ -77,12 +86,18 @@ impl super::Instance {
let render_devid =
libc::makedev(drm_props.render_major as _, drm_props.render_minor as _);

// Various platforms use different widths between `dev_t` and `c_int`, so just
// force-convert to `u64` to keep things portable.
// On most platforms, both `*_devid`s and `st_rdev` are `dev_t`s (which is generally
// observed to be an unsigned integral type no greater than 64 bits). However, on some
// platforms, there divergences from this pattern:
//
// - `armv7-linux-androideabi`: `dev_t` is `c_ulong`, and `*_devid`s are `dev_t`, but
// `st_rdev` is `c_ulonglong`. So, we can't just do a `==` comparison.
// - OpenBSD has `dev_t` on both sides, but is unsigned. Therefore, we can't just use
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsigned, and on 32-bits according to @semarie (our resident rust expert)

// `u64::from`.
#[allow(clippy::useless_conversion)]
if [primary_devid, render_devid]
.map(u64::from)
.contains(&drm_stat.st_rdev)
.map(|devid| to_u64!(devid))
.contains(&to_u64!(drm_stat.st_rdev))
{
physical_device = Some(device)
}
Expand Down
Loading