Skip to content

Commit ae5dc0e

Browse files
authored
Target Specific Compilation (#7076)
1 parent f781a6b commit ae5dc0e

File tree

22 files changed

+535
-157
lines changed

22 files changed

+535
-157
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ also allows more easily creating these structures inline.
5151

5252
By @cwfitzgerald in [#7133](https://github.com/gfx-rs/wgpu/pull/7133)
5353

54+
#### All Backends Now Have Features
55+
56+
Previously, the `vulkan` and `gles` backends were non-optional on windows, linux, and android and there was no way to disable them. We have now figured out how to properly make them disablable! Additionally, if you turn on the `webgl` feature, you will only get the GLES backend on WebAssembly, it won't leak into native builds, like previously it might have.
57+
58+
By @cwfitzgerald in [#7076](https://github.com/gfx-rs/wgpu/pull/7076).
59+
5460
#### `device.poll` Api Reworked
5561

5662
This release reworked the poll api significantly to allow polling to return errors when polling hits internal timeout limits.

Cargo.lock

Lines changed: 32 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ members = [
1616
"player",
1717
"tests",
1818
"wgpu-core",
19+
"wgpu-core/platform-deps/*",
1920
"wgpu-hal",
2021
"wgpu-info",
2122
"wgpu-macros",
@@ -35,6 +36,7 @@ default-members = [
3536
"player",
3637
"tests",
3738
"wgpu-core",
39+
"wgpu-core/platform-deps/*",
3840
"wgpu-hal",
3941
"wgpu-info",
4042
"wgpu-macros",
@@ -74,6 +76,11 @@ wgpu-macros = { version = "24.0.0", path = "./wgpu-macros" }
7476
wgpu-test = { version = "24.0.0", path = "./tests" }
7577
wgpu-types = { version = "24.0.0", path = "./wgpu-types" }
7678

79+
wgpu-core-deps-windows-linux-android = { version = "24.0.0", path = "./wgpu-core/platform-deps/windows-linux-android" }
80+
wgpu-core-deps-apple = { version = "24.0.0", path = "./wgpu-core/platform-deps/apple" }
81+
wgpu-core-deps-wasm = { version = "24.0.0", path = "./wgpu-core/platform-deps/wasm" }
82+
wgpu-core-deps-emscripten = { version = "24.0.0", path = "./wgpu-core/platform-deps/emscripten" }
83+
7784
anyhow = { version = "1.0.95", default-features = false }
7885
approx = "0.5"
7986
argh = "0.1.13"

wgpu-core/Cargo.toml

Lines changed: 73 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ unexpected_cfgs = { level = "warn", check-cfg = ['cfg(wgpu_validate_locks)'] }
3535
[lib]
3636

3737
[features]
38-
## Internally count resources and events for debugging purposes. If the counters
39-
## feature is disabled, the counting infrastructure is removed from the build and
40-
## the exposed counters always return 0.
41-
counters = ["wgpu-types/counters"]
38+
#! See docuemntation for the `wgpu` crate for more in-depth information on these features.
39+
40+
#! ### Logging Configuration
41+
# --------------------------------------------------------------------
4242

4343
## Log all API entry points at info instead of trace level.
4444
## Also, promotes certain debug log calls to info.
@@ -47,33 +47,44 @@ api_log_info = []
4747
## Log resource lifecycle management at info instead of trace level.
4848
resource_log_info = []
4949

50-
## Support the Renderdoc graphics debugger:
51-
## <https://renderdoc.org/>
52-
renderdoc = ["wgpu-hal/renderdoc"]
50+
#! ### Runtime Checks
51+
# --------------------------------------------------------------------
52+
53+
## Validates indirect draw/dispatch calls. This will also enable naga's
54+
## WGSL frontend since we use a WGSL compute shader to do the validation.
55+
indirect-validation = ["naga/wgsl-in"]
5356

5457
## Apply run-time checks, even in release builds. These are in addition
5558
## to the validation carried out at public APIs in all builds.
5659
strict_asserts = ["wgpu-types/strict_asserts"]
5760

58-
## Validates indirect draw/dispatch calls. This will also enable naga's
59-
## WGSL frontend since we use a WGSL compute shader to do the validation.
60-
indirect-validation = ["naga/wgsl-in"]
61+
#! ### Debugging
62+
# --------------------------------------------------------------------
63+
64+
## Enable lock order observation.
65+
observe_locks = ["dep:ron", "serde/serde_derive"]
66+
67+
#! ### Serialization
68+
# --------------------------------------------------------------------
6169

6270
## Enables serialization via `serde` on common wgpu types.
6371
serde = ["dep:serde", "wgpu-types/serde", "arrayvec/serde", "hashbrown/serde"]
6472

6573
## Enable API tracing.
6674
trace = ["dep:ron", "serde", "naga/serialize"]
6775

68-
## Enable lock order observation.
69-
observe_locks = ["dep:ron", "serde/serde_derive"]
70-
7176
## Enable API replaying
7277
replay = ["serde", "naga/deserialize"]
7378

74-
## Enable creating instances using raw-window-handle
79+
#! ### Surface Support
80+
# --------------------------------------------------------------------
81+
82+
## Enable creating surfaces using raw-window-handle
7583
raw-window-handle = ["dep:raw-window-handle"]
7684

85+
#! ### Shading Language Support
86+
# --------------------------------------------------------------------
87+
7788
## Enable `ShaderModuleSource::Wgsl`
7889
wgsl = ["naga/wgsl-in"]
7990

@@ -83,40 +94,68 @@ glsl = ["naga/glsl-in"]
8394
## Enable `ShaderModuleSource::SpirV`
8495
spirv = ["naga/spv-in", "dep:bytemuck"]
8596

97+
#! ### Other
98+
# --------------------------------------------------------------------
99+
100+
## Internally count resources and events for debugging purposes. If the counters
101+
## feature is disabled, the counting infrastructure is removed from the build and
102+
## the exposed counters always return 0.
103+
counters = ["wgpu-types/counters"]
104+
86105
## Implement `Send` and `Sync` on Wasm, but only if atomics are not enabled.
87-
##
88-
## WebGL/WebGPU objects can not be shared between threads.
89-
## However, it can be useful to artificially mark them as `Send` and `Sync`
90-
## anyways to make it easier to write cross-platform code.
91-
## This is technically *very* unsafe in a multithreaded environment,
92-
## but on a wasm binary compiled without atomics we know we are definitely
93-
## not in a multithreaded environment.
94106
fragile-send-sync-non-atomic-wasm = [
95107
"wgpu-hal/fragile-send-sync-non-atomic-wasm",
96-
"wgpu-types/fragile-send-sync-non-atomic-wasm",
97108
]
98109

99-
#! ### Backends, passed through to wgpu-hal
110+
#! ### External libraries
100111
# --------------------------------------------------------------------
112+
#! The following features facilitate integration with third-party supporting libraries.
101113

102-
## Enable the `metal` backend.
103-
metal = ["wgpu-hal/metal"]
114+
## Enable using the `mach-dxcompiler-rs` crate to compile DX12 shaders.
115+
static-dxc = ["wgpu-hal/static-dxc"]
104116

105-
## Enable the `vulkan` backend.
106-
vulkan = ["wgpu-hal/vulkan"]
107-
108-
## Enable the `GLES` backend.
109-
##
110-
## This is used for all of GLES, OpenGL, and WebGL.
111-
gles = ["wgpu-hal/gles"]
117+
#! ### Target Conditional Features
118+
# --------------------------------------------------------------------
119+
# Look to wgpu-hal's Cargo.toml for explaination how these features and the wgpu-core
120+
# platform crates collude to provide platform-specific behavior.
121+
122+
## DX12 backend
123+
dx12 = ["wgpu-core-deps-windows-linux-android/dx12"]
124+
## Metal backend
125+
metal = ["wgpu-core-deps-apple/metal"]
126+
## Vulkan backend, only available on Windows, Linux, Android
127+
vulkan = ["wgpu-core-deps-windows-linux-android/vulkan"]
128+
## OpenGL backend, only available on Windows, Linux, Android, and Emscripten
129+
gles = [
130+
"wgpu-core-deps-windows-linux-android/gles",
131+
"wgpu-core-deps-emscripten/gles",
132+
]
112133

113-
## Enable the `dx12` backend.
114-
dx12 = ["wgpu-hal/dx12"]
134+
## WebGL backend, only available on Emscripten
135+
webgl = ["wgpu-core-deps-wasm/webgl"]
136+
## OpenGL backend, on macOS only
137+
angle = ["wgpu-core-deps-apple/angle"]
138+
## Vulkan portability backend, only available on macOS
139+
vulkan-portability = ["wgpu-core-deps-apple/vulkan-portability"]
140+
## Renderdoc integration, only available on Windows, Linux, and Android
141+
renderdoc = ["wgpu-core-deps-windows-linux-android/renderdoc"]
115142

116143
## Enable the `noop` backend.
117144
# TODO(https://github.com/gfx-rs/wgpu/issues/7120): there should be a hal feature
118145
noop = []
119146

147+
# The target limitation here isn't needed, but prevents more than one of these
148+
# platform crates from being included in the build at a time, preventing users
149+
# from getting confused by seeing them in the list of crates.
150+
[target.'cfg(target_vendor = "apple")'.dependencies]
151+
wgpu-core-deps-apple = { workspace = true, optional = true }
152+
[target.'cfg(target_os = "emscripten")'.dependencies]
153+
wgpu-core-deps-emscripten = { workspace = true, optional = true }
154+
[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies]
155+
wgpu-core-deps-wasm = { workspace = true, optional = true }
156+
[target.'cfg(any(windows, target_os = "linux", target_os = "android"))'.dependencies]
157+
wgpu-core-deps-windows-linux-android = { workspace = true, optional = true }
158+
120159
[dependencies]
121160
naga.workspace = true
122161
wgpu-hal.workspace = true

wgpu-core/build.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
fn main() {
22
cfg_aliases::cfg_aliases! {
3+
windows_linux_android: { any(windows, target_os = "linux", target_os = "android") },
34
send_sync: { any(
45
not(target_arch = "wasm32"),
56
all(feature = "fragile-send-sync-non-atomic-wasm", not(target_feature = "atomics"))
67
) },
7-
webgl: { all(target_arch = "wasm32", not(target_os = "emscripten"), gles) },
88
dx12: { all(target_os = "windows", feature = "dx12") },
9-
gles: { all(feature = "gles") },
9+
webgl: { all(target_arch = "wasm32", not(target_os = "emscripten"), feature = "webgl") },
10+
gles: { any(
11+
all(windows_linux_android, feature = "gles"), // Regular GLES
12+
all(webgl), // WebGL
13+
all(target_os = "emscripten", feature = "gles"), // Emscripten GLES
14+
all(target_vendor = "apple", feature = "angle") // ANGLE on Apple
15+
) },
16+
vulkan: { any(
17+
all(windows_linux_android, feature = "vulkan"), // Regular Vulkan
18+
all(target_vendor = "apple", feature = "vulkan-portability") // Vulkan Portability on Apple
19+
) },
1020
metal: { all(target_vendor = "apple", feature = "metal") },
11-
vulkan: { all(not(target_arch = "wasm32"), feature = "vulkan") }
1221
}
1322
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[package]
2+
name = "wgpu-core-deps-apple"
3+
version.workspace = true
4+
authors.workspace = true
5+
edition.workspace = true
6+
description = "Feature unification helper crate for Apple platforms"
7+
homepage.workspace = true
8+
repository.workspace = true
9+
keywords.workspace = true
10+
license.workspace = true
11+
readme = "README.md"
12+
13+
# Override the workspace's `rust-version` key. Firefox uses `cargo vendor` to
14+
# copy the crates it actually uses out of the workspace, so it's meaningful for
15+
# them to have less restrictive MSRVs individually than the workspace as a
16+
# whole, if their code permits. See `../README.md` for details.
17+
rust-version = "1.76"
18+
19+
[features]
20+
metal = ["wgpu-hal/metal"]
21+
angle = ["wgpu-hal/gles", "wgpu-hal/renderdoc"]
22+
vulkan-portability = ["wgpu-hal/vulkan", "wgpu-hal/renderdoc"]
23+
24+
# Depend on wgpu-hal conditionally, so that the above features only apply to wgpu-hal on this set of platforms.
25+
[target.'cfg(target_vendor = "apple")'.dependencies]
26+
wgpu-hal.workspace = true
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This crate exists to allow platform and feature specific features work correctly. The features
2+
enabled on this crate are only enabled on `target_vendor = "apple"` platforms. See wgpu-hal's `Cargo.toml`
3+
for more information.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//! This crate exists to allow platform and feature specific features work correctly. The features
2+
//! enabled on this crate are only enabled on `target_vendor = "apple"` platforms. See wgpu-hal's `Cargo.toml`
3+
//! for more information.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[package]
2+
name = "wgpu-core-deps-emscripten"
3+
version.workspace = true
4+
authors.workspace = true
5+
edition.workspace = true
6+
description = "Feature unification helper crate for the Emscripten platform"
7+
homepage.workspace = true
8+
repository.workspace = true
9+
keywords.workspace = true
10+
license.workspace = true
11+
readme = "README.md"
12+
13+
# Override the workspace's `rust-version` key. Firefox uses `cargo vendor` to
14+
# copy the crates it actually uses out of the workspace, so it's meaningful for
15+
# them to have less restrictive MSRVs individually than the workspace as a
16+
# whole, if their code permits. See `../README.md` for details.
17+
rust-version = "1.76"
18+
19+
[features]
20+
gles = ["wgpu-hal/gles"]
21+
22+
# Depend on wgpu-hal conditionally, so that the above features only apply to wgpu-hal on this set of platforms.
23+
[target.'cfg(target_os = "emscripten")'.dependencies]
24+
wgpu-hal.workspace = true
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This crate exists to allow platform and feature specific features work correctly. The features
2+
enabled on this crate are only enabled on `target_os = "emscripten"` platforms.
3+
See wgpu-hal's `Cargo.toml` for more information.

0 commit comments

Comments
 (0)