mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-01-11 15:07:58 -05:00
Update enabled_backend_features to take improved backend feature flags into account (#7195)
This commit is contained in:
@@ -1,16 +1,45 @@
|
||||
fn main() {
|
||||
cfg_aliases::cfg_aliases! {
|
||||
native: { not(target_arch = "wasm32") },
|
||||
webgl: { all(target_arch = "wasm32", not(target_os = "emscripten"), feature = "webgl") },
|
||||
webgpu: { all(target_arch = "wasm32", not(target_os = "emscripten"), feature = "webgpu") },
|
||||
Emscripten: { all(target_arch = "wasm32", target_os = "emscripten") },
|
||||
wgpu_core: { any(native, webgl, Emscripten) },
|
||||
|
||||
send_sync: { any(
|
||||
not(target_arch = "wasm32"),
|
||||
native,
|
||||
all(feature = "fragile-send-sync-non-atomic-wasm", not(target_feature = "atomics"))
|
||||
) },
|
||||
|
||||
// Backends - keep this in sync with `wgpu-core/Cargo.toml` & docs in `wgpu/Cargo.toml`
|
||||
webgpu: { all(not(native), not(Emscripten), feature = "webgpu") },
|
||||
webgl: { all(not(native), not(Emscripten), feature = "webgl") },
|
||||
dx12: { all(target_os = "windows", feature = "dx12") },
|
||||
metal: { all(target_vendor = "apple", feature = "metal") },
|
||||
vulkan: { any(
|
||||
// The `vulkan` feature enables the Vulkan backend only on "native Vulkan" platforms, i.e. Windows/Linux/Android
|
||||
all(any(windows, target_os = "linux", target_os = "android"), feature = "vulkan"),
|
||||
// On Apple platforms, however, we require the `vulkan-portability` feature
|
||||
// to explicitly opt-in to Vulkan since it's meant to be used with MoltenVK.
|
||||
all(target_vendor = "apple", feature = "vulkan-portability")
|
||||
) },
|
||||
gles: { any(
|
||||
// The `gles` feature enables the OpenGL/GLES backend only on "native OpenGL" platforms, i.e. Windows, Linux, Android, and Emscripten.
|
||||
// (Note that WebGL is also not included here!)
|
||||
all(any(windows, target_os = "linux", target_os = "android", Emscripten), feature = "gles"),
|
||||
// On Apple platforms, however, we require the `angle` feature to explicitly opt-in to OpenGL
|
||||
// since its meant to be used with ANGLE.
|
||||
all(target_vendor = "apple", feature = "angle")
|
||||
) },
|
||||
noop: { feature = "noop" },
|
||||
|
||||
wgpu_core: {
|
||||
any(
|
||||
// On native, wgpu_core is currently always enabled, even if there's no backend enabled at all.
|
||||
native,
|
||||
// `wgpu_core` is implied if any backend other than WebGPU is enabled.
|
||||
// (this is redundant except for `gles` and `noop`)
|
||||
webgl, dx12, metal, vulkan, gles, noop
|
||||
)
|
||||
},
|
||||
|
||||
// This alias is _only_ if _we_ need naga in the wrapper. wgpu-core provides
|
||||
// its own re-export of naga, which can be used in other situations
|
||||
naga: { any(feature = "naga-ir", feature = "spirv", feature = "glsl") },
|
||||
|
||||
@@ -62,45 +62,27 @@ impl Instance {
|
||||
///
|
||||
/// `InstanceDescriptor::backends` does not need to be a subset of this,
|
||||
/// but any backend that is not in this set, will not be picked.
|
||||
///
|
||||
/// TODO: Right now it's otherwise not possible yet to opt-out of all features on some platforms.
|
||||
/// See <https://github.com/gfx-rs/wgpu/issues/3514>
|
||||
/// * Windows/Linux/Android: always enables Vulkan and GLES with no way to opt out
|
||||
pub const fn enabled_backend_features() -> Backends {
|
||||
let mut backends = Backends::empty();
|
||||
|
||||
if cfg!(native) {
|
||||
if cfg!(metal) {
|
||||
backends = backends.union(Backends::METAL);
|
||||
}
|
||||
if cfg!(dx12) {
|
||||
backends = backends.union(Backends::DX12);
|
||||
}
|
||||
|
||||
// Windows, Android, Linux currently always enable Vulkan and OpenGL.
|
||||
// See <https://github.com/gfx-rs/wgpu/issues/3514>
|
||||
if cfg!(target_os = "windows") || cfg!(unix) {
|
||||
backends = backends.union(Backends::VULKAN).union(Backends::GL);
|
||||
}
|
||||
|
||||
// Vulkan on Mac/iOS is only available through vulkan-portability.
|
||||
if cfg!(target_vendor = "apple") && cfg!(feature = "vulkan-portability") {
|
||||
backends = backends.union(Backends::VULKAN);
|
||||
}
|
||||
|
||||
// GL on Mac is only available through angle.
|
||||
if cfg!(target_os = "macos") && cfg!(feature = "angle") {
|
||||
backends = backends.union(Backends::GL);
|
||||
}
|
||||
} else {
|
||||
if cfg!(webgpu) {
|
||||
backends = backends.union(Backends::BROWSER_WEBGPU);
|
||||
}
|
||||
if cfg!(webgl) {
|
||||
backends = backends.union(Backends::GL);
|
||||
}
|
||||
// `.set` and `|=` don't work in a `const` context.
|
||||
if cfg!(noop) {
|
||||
backends = backends.union(Backends::NOOP);
|
||||
}
|
||||
if cfg!(vulkan) {
|
||||
backends = backends.union(Backends::VULKAN);
|
||||
}
|
||||
if cfg!(any(gles, webgl)) {
|
||||
backends = backends.union(Backends::GL);
|
||||
}
|
||||
if cfg!(metal) {
|
||||
backends = backends.union(Backends::METAL);
|
||||
}
|
||||
if cfg!(dx12) {
|
||||
backends = backends.union(Backends::DX12);
|
||||
}
|
||||
if cfg!(webgpu) {
|
||||
backends = backends.union(Backends::BROWSER_WEBGPU);
|
||||
}
|
||||
|
||||
backends
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user