Skip to content

Commit 9ad01d1

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, with appropriate platform qualifications.
1 parent bde7091 commit 9ad01d1

13 files changed

Lines changed: 41 additions & 33 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ Bottom level categories:
7070
#### Vulkan
7171

7272
- Add `vulkan::Device::texture_from_dmabuf_fd()` for importing DMA-buf textures on Linux, with `VULKAN_EXTERNAL_MEMORY_FD` and `VULKAN_EXTERNAL_MEMORY_DMA_BUF` feature flags. By @TODO in [#TODO](https://github.com/gfx-rs/wgpu/pull/TODO).
73-
- Add support for RawWindowHandle::Drm on unix. By @rectalogic in [#9182](https://github.com/gfx-rs/wgpu/pull/9182).
73+
- Add support for RawWindowHandle::Drm on unix, conditional on the `"drm"` feature.
74+
- DRM support by @rectalogic in [#9182](https://github.com/gfx-rs/wgpu/pull/9182).
75+
- Conditional compilation by @jimblandy in [#9390](https://github.com/gfx-rs/wgpu/pull/9390)
7476

7577
### Changes
7678

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/build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ fn main() {
2020
all(windows_linux_android, feature = "vulkan"), // Regular Vulkan
2121
all(target_vendor = "apple", feature = "vulkan-portability") // Vulkan Portability on Apple
2222
) },
23+
drm: { all(
24+
feature = "drm",
25+
any(target_os = "linux", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd")
26+
) },
2327
metal: { all(target_vendor = "apple", feature = "metal") },
2428

2529
supports_64bit_atomics: { target_has_atomic = "64" }

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: 8 additions & 16 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(drm)]
272268
#[cfg_attr(not(vulkan), expect(unused_variables))]
273269
pub unsafe fn create_surface_from_drm(
274270
&self,
@@ -966,14 +962,10 @@ impl Global {
966962
///
967963
/// # Platform Support
968964
///
969-
/// This function is only available on non-apple Unix-like platforms (Linux, FreeBSD) and
970-
/// 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-
))]
965+
/// This function requires the `"drm"` feature, and is only available on
966+
/// non-apple Unix-like platforms (Linux, FreeBSD) and currently only works
967+
/// with the Vulkan backend.
968+
#[cfg(drm)]
977969
pub unsafe fn instance_create_surface_from_drm(
978970
&self,
979971
fd: i32,

wgpu-hal/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ vulkan = [
9393
"dep:arrayvec",
9494
"dep:ash",
9595
"dep:bytemuck",
96-
"dep:drm",
9796
"dep:gpu-descriptor",
9897
"dep:libc",
9998
"dep:libloading",
@@ -251,6 +250,7 @@ wayland-sys = { version = "0.31.3", features = [
251250
"egl",
252251
], optional = true }
253252

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

wgpu-hal/build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ fn main() {
2323
) },
2424
metal: { all(target_vendor = "apple", feature = "metal") },
2525
vulkan: { all(not(target_arch = "wasm32"), feature = "vulkan") },
26+
drm: { all(
27+
feature = "drm",
28+
any(target_os = "linux", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd")
29+
) },
2630
any_backend: { any(dx12, metal, vulkan, gles) },
2731
// ⚠️ Keep in sync with target.cfg() definition in Cargo.toml and cfg_alias in `wgpu` crate ⚠️
2832
static_dxc: { all(target_os = "windows", feature = "static-dxc", not(target_arch = "aarch64"), target_env = "msvc") },

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(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!(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(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,

0 commit comments

Comments
 (0)