Skip to content

Commit 9d14871

Browse files
Fix OpenBSD compilation of wgpu_hal::vulkan::drm (#7810)
1 parent 402a479 commit 9d14871

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ Bottom level categories:
8888

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

91+
#### Vulkan
92+
93+
- Fix OpenBSD compilation of `wgpu_hal::vulkan::drm`. By @ErichDonGubler in [#7810](https://github.com/gfx-rs/wgpu/pull/7810).
94+
9195
#### Metal
9296

9397
- Remove extraneous main thread warning in `fn surface_capabilities()`. By @jamesordner in [#7692](https://github.com/gfx-rs/wgpu/pull/7692)

wgpu-hal/src/vulkan/drm.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ use core::mem::MaybeUninit;
55

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

8+
macro_rules! to_u64 {
9+
($expr:expr) => {{
10+
#[allow(trivial_numeric_casts)]
11+
let expr = $expr as u64;
12+
assert!(size_of_val(&expr) <= size_of::<u64>());
13+
expr
14+
}};
15+
}
16+
817
impl super::Instance {
918
/// Creates a new surface from the given drm configuration.
1019
///
@@ -77,12 +86,18 @@ impl super::Instance {
7786
let render_devid =
7887
libc::makedev(drm_props.render_major as _, drm_props.render_minor as _);
7988

80-
// Various platforms use different widths between `dev_t` and `c_int`, so just
81-
// force-convert to `u64` to keep things portable.
89+
// On most platforms, both `*_devid`s and `st_rdev` are `dev_t`s (which is generally
90+
// observed to be an unsigned integral type no greater than 64 bits). However, on some
91+
// platforms, there divergences from this pattern:
92+
//
93+
// - `armv7-linux-androideabi`: `dev_t` is `c_ulong`, and `*_devid`s are `dev_t`, but
94+
// `st_rdev` is `c_ulonglong`. So, we can't just do a `==` comparison.
95+
// - OpenBSD has `dev_t` on both sides, but is `i32` (N.B., unsigned). Therefore, we
96+
// can't just use `u64::from`.
8297
#[allow(clippy::useless_conversion)]
8398
if [primary_devid, render_devid]
84-
.map(u64::from)
85-
.contains(&drm_stat.st_rdev)
99+
.map(|devid| to_u64!(devid))
100+
.contains(&to_u64!(drm_stat.st_rdev))
86101
{
87102
physical_device = Some(device)
88103
}

0 commit comments

Comments
 (0)