Skip to content

Commit 367da11

Browse files
committed
Make DRM support optional.
The DRM API is for interacting with GPUs and displays directly via system calls, without going through something like Mesa. Very few `wgpu` users are driving hardware directly, and those that are are sophisticated users, capable of finding and requesting the feature themselves. Supporting DRM in `wgpu_hal` adds dependencies on `drm` and its supporting crates. The crates seem fine, but they do contribute to download and build time. Firefox definitely does not want to have to vendor `drm` and its subcrates into its source tree, since Firefox should never be interacting with graphics hardware directly. In `wgpu_hal`, make support for `RawWindowHandle::Drm` and `RawDisplayHandle::Drm` require that the `"drm"` feature be explicitly requested, rather than supporting DRM handles by default. Add a `"drm"` feature to `wgpu`, `wgpu-core`, and `wgpu-core-deps-windows-linux-android`, and make the relevant glue code conditional on that.
1 parent 9c49f92 commit 367da11

9 files changed

Lines changed: 38 additions & 34 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ Bottom level categories:
6262

6363
#### Vulkan
6464

65-
- Add support for RawWindowHandle::Drm on unix. By @rectalogic in [#9182](https://github.com/gfx-rs/wgpu/pull/9182).
65+
- Add support for RawWindowHandle::Drm on unix, conditional on the `"drm"` feature.
66+
- DRM support by @rectalogic in [#9182](https://github.com/gfx-rs/wgpu/pull/9182).
67+
- Conditional compilation by @jimblandy in [#9390](https://github.com/gfx-rs/wgpu/pull/9390)
6668

6769
### Changes
6870

wgpu-core/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ vulkan-portability = ["wgpu-core-deps-apple/vulkan-portability"]
149149
## Renderdoc integration, only available on Windows, Linux, and Android
150150
renderdoc = ["wgpu-core-deps-windows-linux-android/renderdoc"]
151151

152+
## Support creating textures from DRM display/window handles.
153+
drm = ["wgpu-core-deps-windows-linux-android/drm"]
154+
152155
## Enable the `noop` backend.
153156
# TODO(https://github.com/gfx-rs/wgpu/issues/7120): there should be a hal feature
154157
noop = []

wgpu-core/platform-deps/windows-linux-android/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ vulkan = ["wgpu-hal/vulkan"]
2222
dx12 = ["wgpu-hal/dx12"]
2323
renderdoc = ["wgpu-hal/renderdoc"]
2424

25+
## Support creating textures from DRM display/window handles.
26+
drm = ["wgpu-hal/drm"]
27+
2528
# Depend on wgpu-hal conditionally, so that the above features only apply to wgpu-hal on this set of platforms.
2629
[target.'cfg(any(windows, target_os = "linux", target_os = "android", target_os = "freebsd", target_os = "netbsd"))'.dependencies]
2730
wgpu-hal.workspace = true

wgpu-core/src/instance.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,10 @@ impl Instance {
261261
///
262262
/// # Platform Support
263263
///
264-
/// This function is only available on non-apple Unix-like platforms (Linux, FreeBSD) and
265-
/// currently only works with the Vulkan backend.
266-
#[cfg(all(
267-
unix,
268-
not(target_vendor = "apple"),
269-
not(target_family = "wasm"),
270-
not(target_os = "netbsd")
271-
))]
264+
/// This function requires the `"drm"` feature. It is only available on
265+
/// non-apple Unix-like platforms (Linux, FreeBSD) and currently only works
266+
/// with the Vulkan backend.
267+
#[cfg(feature = "drm")]
272268
#[cfg_attr(not(vulkan), expect(unused_variables))]
273269
pub unsafe fn create_surface_from_drm(
274270
&self,
@@ -968,12 +964,7 @@ impl Global {
968964
///
969965
/// This function is only available on non-apple Unix-like platforms (Linux, FreeBSD) and
970966
/// currently only works with the Vulkan backend.
971-
#[cfg(all(
972-
unix,
973-
not(target_vendor = "apple"),
974-
not(target_family = "wasm"),
975-
not(target_os = "netbsd")
976-
))]
967+
#[cfg(feature = "drm")]
977968
pub unsafe fn instance_create_surface_from_drm(
978969
&self,
979970
fd: i32,

wgpu-hal/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ vulkan = [
9494
"dep:arrayvec",
9595
"dep:ash",
9696
"dep:bytemuck",
97-
"dep:drm",
9897
"dep:gpu-descriptor",
9998
"dep:hashbrown",
10099
"dep:libc",
@@ -252,6 +251,7 @@ wayland-sys = { version = "0.31.3", features = [
252251
"egl",
253252
], optional = true }
254253

254+
## Support creating textures from DRM display/window handles.
255255
[target.'cfg(all(unix, not(target_vendor = "apple"), not(target_family = "wasm")))'.dependencies]
256256
drm = { version = "0.15", optional = true }
257257

wgpu-hal/src/vulkan/drm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![cfg(all(unix, not(target_vendor = "apple"), not(target_family = "wasm")))]
1+
#![cfg(feature = "drm")]
22

33
use alloc::{string::ToString, vec::Vec};
44
use core::{mem::MaybeUninit, num::NonZeroU32};

wgpu-hal/src/vulkan/instance.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,7 @@ impl super::Instance {
264264
extensions.push(ext::metal_surface::NAME);
265265
extensions.push(khr::portability_enumeration::NAME);
266266
}
267-
if cfg!(all(
268-
unix,
269-
not(target_vendor = "apple"),
270-
not(target_family = "wasm")
271-
)) {
267+
if cfg!(feature = "drm") {
272268
// VK_EXT_acquire_drm_display -> VK_EXT_direct_mode_display -> VK_KHR_display
273269
extensions.push(ext::acquire_drm_display::NAME);
274270
extensions.push(ext::direct_mode_display::NAME);
@@ -892,7 +888,7 @@ impl crate::Instance for super::Instance {
892888
let connection = display.connection.expect("Pointer to X-Server is not set.");
893889
self.create_surface_from_xcb(connection.as_ptr(), handle.window.get())
894890
}
895-
#[cfg(all(unix, not(target_vendor = "apple"), not(target_family = "wasm")))]
891+
#[cfg(feature = "drm")]
896892
(Rwh::Drm(handle), Rdh::Drm(display)) => {
897893
self.create_surface_from_drm_plane(display.fd, handle.plane)
898894
}

wgpu/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ vulkan-portability = ["wgpu-core?/vulkan-portability"]
8585
## Enables the GLES backend on WebAssembly only.
8686
webgl = ["web", "wgpu-core/webgl", "dep:wgpu-hal", "dep:smallvec"]
8787

88+
#! ### Backend features
89+
90+
## Support creating textures from DRM display/window handles.
91+
drm = ["wgpu-core/drm"]
92+
8893
## Enables the noop backend for testing.
8994
##
9095
## This backend allows creating resources such as buffers and textures,

wgpu/src/backend/wgpu_core.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -792,12 +792,21 @@ impl dispatch::InstanceInterface for ContextWgpuCore {
792792
.instance_create_surface(raw_display_handle, raw_window_handle, None)
793793
},
794794

795-
#[cfg(all(
796-
unix,
797-
not(target_vendor = "apple"),
798-
not(target_family = "wasm"),
799-
not(target_os = "netbsd")
800-
))]
795+
#[cfg(target_os = "netbsd")]
796+
SurfaceTargetUnsafe::Drm { .. } => Err(
797+
wgc::instance::CreateSurfaceError::BackendNotEnabled(wgt::Backend::Vulkan),
798+
),
799+
800+
#[cfg(not(any(feature = "drm", target_os = "netbsd")))]
801+
SurfaceTargetUnsafe::Drm { .. } => {
802+
return Err(crate::CreateSurfaceError {
803+
inner: crate::CreateSurfaceErrorKind::RawHandle(
804+
raw_window_handle::HandleError::NotSupported,
805+
),
806+
});
807+
}
808+
809+
#[cfg(any(feature = "drm", target_os = "netbsd"))]
801810
SurfaceTargetUnsafe::Drm {
802811
fd,
803812
plane,
@@ -822,11 +831,6 @@ impl dispatch::InstanceInterface for ContextWgpuCore {
822831
self.0.instance_create_surface_metal(layer, None)
823832
},
824833

825-
#[cfg(target_os = "netbsd")]
826-
SurfaceTargetUnsafe::Drm { .. } => Err(
827-
wgc::instance::CreateSurfaceError::BackendNotEnabled(wgt::Backend::Vulkan),
828-
),
829-
830834
#[cfg(dx12)]
831835
SurfaceTargetUnsafe::CompositionVisual(visual) => unsafe {
832836
self.0.instance_create_surface_from_visual(visual, None)

0 commit comments

Comments
 (0)