Make wgpu-core users responsible for choosing back ends. (#3254)

This commit is contained in:
Jim Blandy authored and GitHub committed 2022-12-07 20:58:45 -05:00
1 parent 3d33ace8d7
commit a50836e0cb
12 files changed
+254 -191

No files matched your search

+10 -3
View File
@@ -159,11 +159,18 @@ jobs:
# check with no features
cargo clippy --target ${{ matrix.target }} -p wgpu -p wgpu-core -p wgpu-info -p player --no-default-features
# check with all features
cargo clippy --target ${{ matrix.target }} -p wgpu -p wgpu-core -p wgpu-info -p player --tests --all-features
# Check with all features.
# (But watch out for backend-selection features in wgpu-core; some of
# those only build on the right platforms.)
cargo clippy --target ${{ matrix.target }} -p wgpu -p wgpu-info -p player --tests --all-features
cargo clippy --target ${{ matrix.target }} -p wgpu-core --tests \
--features="portable_features"
# build docs
cargo doc --target ${{ matrix.target }} -p wgpu -p wgpu-core -p wgpu-info -p player --all-features --no-deps
# (Watch out for backend-selection features in wgpu-core; some of
# those only build on the right platforms.)
cargo doc --target ${{ matrix.target }} -p wgpu -p wgpu-info -p player --all-features --no-deps
cargo doc --target ${{ matrix.target }} -p wgpu-core --no-deps --features="portable_features"
gpu-test:
strategy:
+36
View File
@@ -42,6 +42,42 @@ Bottom level categories:
### Major Changes
#### Backend selection by features
Whereas `wgpu-core` used to automatically select backends to enable
based on the target OS and architecture, it now has separate features
to enable each backend:
- "metal", for the Metal API on macOS and iOS
- "vulkan", for the Vulkan API (Linux, some Android, and occasionally Windows)
- "dx12", for Microsoft's Direct3D 12 API
- "gles", OpenGL ES, available on many systems
- "dx11", for Microsoft's Direct3D 11 API
None are enabled by default, but the `wgpu` crate automatically
selects these features based on the target operating system and
architecture, using the same rules that `wgpu-core` used to, so users
of `wgpu` should be unaffected by this change. However, other crates
using `wgpu-core` directly will need to copy `wgpu`'s logic or write
their own. See the `[target]` section of `wgpu/Cargo.toml` for
details.
Similarly, `wgpu-core` now has `emscripten` and `renderdoc` features
that `wgpu` enables on appropriate platforms.
In previous releases, the `wgpu-core` crate decided which backends to
support. However, this left `wgpu-core`'s users with no way to
override those choices. (Firefox doesn't want the GLES back end, for
example.) There doesn't seem to be any way to have a crate select
backends based on target OS and architecture that users of that crate
can still override. Default features can't be selected based on the
target, for example. That implies that we should do the selection as
late in the dependency DAG as feasible. Having `wgpu` (and
`wgpu-core`'s other dependents) choose backends seems like the best
option.
By @jimblandy in [#3254](https://github.com/gfx-rs/wgpu/pull/3254).
#### Surface Capabilities API
The various surface capability functions were combined into a single call that gives you all the capabilities.
Generated
-7
View File
@@ -253,12 +253,6 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "cfg_aliases"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e"
[[package]]
name = "cgl"
version = "0.3.2"
@@ -2835,7 +2829,6 @@ dependencies = [
"arrayvec 0.7.2",
"bit-vec",
"bitflags",
"cfg_aliases",
"codespan-reporting",
"fxhash",
"log",
+19 -1
View File
@@ -14,5 +14,23 @@ description = "WebGPU implementation for Deno"
deno_core.workspace = true
serde = { workspace = true, features = ["derive"] }
tokio = { workspace = true, features = ["full"] }
wgpu-core = { workspace = true, features = ["trace", "replay", "serde", "strict_asserts", "wgsl"] }
wgpu-types = { workspace = true, features = ["trace", "replay", "serde"] }
[dependencies.wgpu-core]
workspace = true
features = ["trace", "replay", "serde", "strict_asserts", "wgsl", "gles"]
# We want the wgpu-core Metal backend on macOS and iOS.
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies.wgpu-core]
workspace = true
features = ["metal"]
# We want the wgpu-core Direct3D backends on Windows.
[target.'cfg(windows)'.dependencies.wgpu-core]
workspace = true
features = ["dx11", "dx12"]
# We want the wgpu-core Vulkan backend on Unix (but not Emscripten) and Windows.
[target.'cfg(any(windows, all(unix, not(target_arch = "emscripten"))))'.dependencies.wgpu-core]
workspace = true
features = ["vulkan"]
+18 -19
View File
@@ -17,6 +17,21 @@ rustdoc-args = ["--cfg", "docsrs"]
[features]
default = []
# Backends, passed through to wgpu-hal
metal = ["hal/metal"]
vulkan = ["hal/vulkan"]
gles = ["hal/gles"]
dx11 = ["hal/dx11"]
dx12 = ["hal/dx12"]
# Support the Renderdoc graphics debugger:
# https://renderdoc.org/
renderdoc = ["hal/renderdoc"]
# Compile for the Emscripten POSIX-in-a-web-page emulation environment.
emscripten = ["hal/emscripten"]
# Apply run-time checks, even in release builds. These are in addition
# to the validation carried out at public APIs in all builds.
strict_asserts = []
@@ -32,6 +47,9 @@ id32 = []
wgsl = ["naga/wgsl-in"]
vulkan-portability = ["hal/vulkan"]
# Features that are intended to work on all platforms.
portable_features = ["gles", "strict_asserts", "trace", "replay", "serial-pass", "id32", "wgsl"]
[dependencies]
arrayvec.workspace = true
bitflags.workspace = true
@@ -59,22 +77,3 @@ workspace = true
[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies]
web-sys = { workspace = true, features = ["HtmlCanvasElement", "OffscreenCanvas"] }
[target.'cfg(target_arch = "wasm32")'.dependencies]
hal = { workspace = true, features = ["gles"] }
[target.'cfg(all(not(target_arch = "wasm32"), any(target_os = "ios", target_os = "macos")))'.dependencies]
hal = { workspace = true, features = ["metal"] }
#Note: could also enable "vulkan" for Vulkan Portability
[target.'cfg(all(not(target_arch = "wasm32"), unix, not(target_os = "ios"), not(target_os = "macos")))'.dependencies]
hal = { workspace = true, features = ["vulkan", "gles", "renderdoc"] }
[target.'cfg(all(not(target_arch = "wasm32"), windows))'.dependencies]
hal = { workspace = true, features = ["vulkan", "dx12", "dx11", "renderdoc"] }
[target.'cfg(target_os = "emscripten")'.dependencies]
hal = { workspace = true, features = ["emscripten"] }
[build-dependencies]
cfg_aliases.workspace = true
-22
View File
@@ -1,22 +0,0 @@
fn main() {
// Setup cfg aliases
cfg_aliases::cfg_aliases! {
// Vendors/systems
wasm: { target_arch = "wasm32" },
apple: { any(target_os = "ios", target_os = "macos") },
unix_wo_apple: {all(unix, not(apple))},
// Backends
vulkan: { all(not(wasm), any(windows, unix_wo_apple, feature = "vulkan-portability")) },
metal: { all(not(wasm), apple) },
dx12: { all(not(wasm), windows) },
dx11: { all(not(wasm), windows) },
gl: {
any(
unix_wo_apple,
feature = "angle",
wasm
)
},
}
}
+5 -5
View File
@@ -5407,27 +5407,27 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let mut closures = UserClosures::default();
let mut all_queue_empty = true;
#[cfg(vulkan)]
#[cfg(feature = "vulkan")]
{
all_queue_empty = self.poll_devices::<hal::api::Vulkan>(force_wait, &mut closures)?
&& all_queue_empty;
}
#[cfg(metal)]
#[cfg(feature = "metal")]
{
all_queue_empty =
self.poll_devices::<hal::api::Metal>(force_wait, &mut closures)? && all_queue_empty;
}
#[cfg(dx12)]
#[cfg(feature = "dx12")]
{
all_queue_empty =
self.poll_devices::<hal::api::Dx12>(force_wait, &mut closures)? && all_queue_empty;
}
#[cfg(dx11)]
#[cfg(feature = "dx11")]
{
all_queue_empty =
self.poll_devices::<hal::api::Dx11>(force_wait, &mut closures)? && all_queue_empty;
}
#[cfg(gl)]
#[cfg(feature = "gles")]
{
all_queue_empty =
self.poll_devices::<hal::api::Gles>(force_wait, &mut closures)? && all_queue_empty;
+30 -30
View File
@@ -1057,30 +1057,30 @@ impl<A: HalApi, F: GlobalIdentityHandlerFactory> Hub<A, F> {
}
pub struct Hubs<F: GlobalIdentityHandlerFactory> {
#[cfg(vulkan)]
#[cfg(feature = "vulkan")]
vulkan: Hub<hal::api::Vulkan, F>,
#[cfg(metal)]
#[cfg(feature = "metal")]
metal: Hub<hal::api::Metal, F>,
#[cfg(dx12)]
#[cfg(feature = "dx12")]
dx12: Hub<hal::api::Dx12, F>,
#[cfg(dx11)]
#[cfg(feature = "dx11")]
dx11: Hub<hal::api::Dx11, F>,
#[cfg(gl)]
#[cfg(feature = "gles")]
gl: Hub<hal::api::Gles, F>,
}
impl<F: GlobalIdentityHandlerFactory> Hubs<F> {
fn new(factory: &F) -> Self {
Self {
#[cfg(vulkan)]
#[cfg(feature = "vulkan")]
vulkan: Hub::new(factory),
#[cfg(metal)]
#[cfg(feature = "metal")]
metal: Hub::new(factory),
#[cfg(dx12)]
#[cfg(feature = "dx12")]
dx12: Hub::new(factory),
#[cfg(dx11)]
#[cfg(feature = "dx11")]
dx11: Hub::new(factory),
#[cfg(gl)]
#[cfg(feature = "gles")]
gl: Hub::new(factory),
}
}
@@ -1089,15 +1089,15 @@ impl<F: GlobalIdentityHandlerFactory> Hubs<F> {
#[derive(Debug)]
pub struct GlobalReport {
pub surfaces: StorageReport,
#[cfg(vulkan)]
#[cfg(feature = "vulkan")]
pub vulkan: Option<HubReport>,
#[cfg(metal)]
#[cfg(feature = "metal")]
pub metal: Option<HubReport>,
#[cfg(dx12)]
#[cfg(feature = "dx12")]
pub dx12: Option<HubReport>,
#[cfg(dx11)]
#[cfg(feature = "dx11")]
pub dx11: Option<HubReport>,
#[cfg(gl)]
#[cfg(feature = "gles")]
pub gl: Option<HubReport>,
}
@@ -1162,31 +1162,31 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
pub fn generate_report(&self) -> GlobalReport {
GlobalReport {
surfaces: self.surfaces.data.read().generate_report(),
#[cfg(vulkan)]
#[cfg(feature = "vulkan")]
vulkan: if self.instance.vulkan.is_some() {
Some(self.hubs.vulkan.generate_report())
} else {
None
},
#[cfg(metal)]
#[cfg(feature = "metal")]
metal: if self.instance.metal.is_some() {
Some(self.hubs.metal.generate_report())
} else {
None
},
#[cfg(dx12)]
#[cfg(feature = "dx12")]
dx12: if self.instance.dx12.is_some() {
Some(self.hubs.dx12.generate_report())
} else {
None
},
#[cfg(dx11)]
#[cfg(feature = "dx11")]
dx11: if self.instance.dx11.is_some() {
Some(self.hubs.dx11.generate_report())
} else {
None
},
#[cfg(gl)]
#[cfg(feature = "gles")]
gl: if self.instance.gl.is_some() {
Some(self.hubs.gl.generate_report())
} else {
@@ -1203,23 +1203,23 @@ impl<G: GlobalIdentityHandlerFactory> Drop for Global<G> {
let mut surface_guard = self.surfaces.data.write();
// destroy hubs before the instance gets dropped
#[cfg(vulkan)]
#[cfg(feature = "vulkan")]
{
self.hubs.vulkan.clear(&mut surface_guard, true);
}
#[cfg(metal)]
#[cfg(feature = "metal")]
{
self.hubs.metal.clear(&mut surface_guard, true);
}
#[cfg(dx12)]
#[cfg(feature = "dx12")]
{
self.hubs.dx12.clear(&mut surface_guard, true);
}
#[cfg(dx11)]
#[cfg(feature = "dx11")]
{
self.hubs.dx11.clear(&mut surface_guard, true);
}
#[cfg(gl)]
#[cfg(feature = "gles")]
{
self.hubs.gl.clear(&mut surface_guard, true);
}
@@ -1261,7 +1261,7 @@ impl HalApi for hal::api::Empty {
}
}
#[cfg(vulkan)]
#[cfg(feature = "vulkan")]
impl HalApi for hal::api::Vulkan {
const VARIANT: Backend = Backend::Vulkan;
fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> Instance {
@@ -1285,7 +1285,7 @@ impl HalApi for hal::api::Vulkan {
}
}
#[cfg(metal)]
#[cfg(feature = "metal")]
impl HalApi for hal::api::Metal {
const VARIANT: Backend = Backend::Metal;
fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> Instance {
@@ -1309,7 +1309,7 @@ impl HalApi for hal::api::Metal {
}
}
#[cfg(dx12)]
#[cfg(feature = "dx12")]
impl HalApi for hal::api::Dx12 {
const VARIANT: Backend = Backend::Dx12;
fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> Instance {
@@ -1333,7 +1333,7 @@ impl HalApi for hal::api::Dx12 {
}
}
#[cfg(dx11)]
#[cfg(feature = "dx11")]
impl HalApi for hal::api::Dx11 {
const VARIANT: Backend = Backend::Dx11;
fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> Instance {
@@ -1357,7 +1357,7 @@ impl HalApi for hal::api::Dx11 {
}
}
#[cfg(gl)]
#[cfg(feature = "gles")]
impl HalApi for hal::api::Gles {
const VARIANT: Backend = Backend::Gl;
fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> Instance {
+51 -51
View File
@@ -54,15 +54,15 @@ fn downlevel_default_limits_less_than_default_limits() {
pub struct Instance {
#[allow(dead_code)]
pub name: String,
#[cfg(vulkan)]
#[cfg(feature = "vulkan")]
pub vulkan: Option<HalInstance<hal::api::Vulkan>>,
#[cfg(metal)]
#[cfg(feature = "metal")]
pub metal: Option<HalInstance<hal::api::Metal>>,
#[cfg(dx12)]
#[cfg(feature = "dx12")]
pub dx12: Option<HalInstance<hal::api::Dx12>>,
#[cfg(dx11)]
#[cfg(feature = "dx11")]
pub dx11: Option<HalInstance<hal::api::Dx11>>,
#[cfg(gl)]
#[cfg(feature = "gles")]
pub gl: Option<HalInstance<hal::api::Gles>>,
}
@@ -87,15 +87,15 @@ impl Instance {
Self {
name: name.to_string(),
#[cfg(vulkan)]
#[cfg(feature = "vulkan")]
vulkan: init(hal::api::Vulkan, backends),
#[cfg(metal)]
#[cfg(feature = "metal")]
metal: init(hal::api::Metal, backends),
#[cfg(dx12)]
#[cfg(feature = "dx12")]
dx12: init(hal::api::Dx12, backends),
#[cfg(dx11)]
#[cfg(feature = "dx11")]
dx11: init(hal::api::Dx11, backends),
#[cfg(gl)]
#[cfg(feature = "gles")]
gl: init(hal::api::Gles, backends),
}
}
@@ -112,30 +112,30 @@ impl Instance {
}
}
}
#[cfg(vulkan)]
#[cfg(feature = "vulkan")]
destroy(hal::api::Vulkan, &self.vulkan, surface.vulkan);
#[cfg(metal)]
#[cfg(feature = "metal")]
destroy(hal::api::Metal, &self.metal, surface.metal);
#[cfg(dx12)]
#[cfg(feature = "dx12")]
destroy(hal::api::Dx12, &self.dx12, surface.dx12);
#[cfg(dx11)]
#[cfg(feature = "dx11")]
destroy(hal::api::Dx11, &self.dx11, surface.dx11);
#[cfg(gl)]
#[cfg(feature = "gles")]
destroy(hal::api::Gles, &self.gl, surface.gl);
}
}
pub struct Surface {
pub(crate) presentation: Option<Presentation>,
#[cfg(vulkan)]
#[cfg(feature = "vulkan")]
pub vulkan: Option<HalSurface<hal::api::Vulkan>>,
#[cfg(metal)]
#[cfg(feature = "metal")]
pub metal: Option<HalSurface<hal::api::Metal>>,
#[cfg(dx12)]
#[cfg(feature = "dx12")]
pub dx12: Option<HalSurface<hal::api::Dx12>>,
#[cfg(dx11)]
#[cfg(feature = "dx11")]
pub dx11: Option<HalSurface<hal::api::Dx11>>,
#[cfg(gl)]
#[cfg(feature = "gles")]
pub gl: Option<HalSurface<hal::api::Gles>>,
}
@@ -451,15 +451,15 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let surface = Surface {
presentation: None,
#[cfg(vulkan)]
#[cfg(feature = "vulkan")]
vulkan: init::<hal::api::Vulkan>(&self.instance.vulkan, display_handle, window_handle),
#[cfg(metal)]
#[cfg(feature = "metal")]
metal: init::<hal::api::Metal>(&self.instance.metal, display_handle, window_handle),
#[cfg(dx12)]
#[cfg(feature = "dx12")]
dx12: init::<hal::api::Dx12>(&self.instance.dx12, display_handle, window_handle),
#[cfg(dx11)]
#[cfg(feature = "dx11")]
dx11: init::<hal::api::Dx11>(&self.instance.dx11, display_handle, window_handle),
#[cfg(gl)]
#[cfg(feature = "gles")]
gl: init::<hal::api::Gles>(&self.instance.gl, display_handle, window_handle),
};
@@ -468,7 +468,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
id.0
}
#[cfg(metal)]
#[cfg(feature = "metal")]
pub fn instance_create_surface_metal(
&self,
layer: *mut std::ffi::c_void,
@@ -486,9 +486,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
},
//acquired_texture: None,
}),
#[cfg(vulkan)]
#[cfg(feature = "vulkan")]
vulkan: None,
#[cfg(gl)]
#[cfg(feature = "gles")]
gl: None,
};
@@ -551,7 +551,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
Ok(id.0)
}
#[cfg(dx12)]
#[cfg(feature = "dx12")]
/// # Safety
///
/// The visual must be valid and able to be used to make a swapchain with.
@@ -564,13 +564,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let surface = Surface {
presentation: None,
#[cfg(vulkan)]
#[cfg(feature = "vulkan")]
vulkan: None,
dx12: self.instance.dx12.as_ref().map(|inst| HalSurface {
raw: unsafe { inst.create_surface_from_visual(visual as _) },
}),
dx11: None,
#[cfg(gl)]
#[cfg(feature = "gles")]
gl: None,
};
@@ -623,25 +623,25 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let mut adapters = Vec::new();
#[cfg(vulkan)]
#[cfg(feature = "vulkan")]
self.enumerate(
hal::api::Vulkan,
&self.instance.vulkan,
&inputs,
&mut adapters,
);
#[cfg(metal)]
#[cfg(feature = "metal")]
self.enumerate(
hal::api::Metal,
&self.instance.metal,
&inputs,
&mut adapters,
);
#[cfg(dx12)]
#[cfg(feature = "dx12")]
self.enumerate(hal::api::Dx12, &self.instance.dx12, &inputs, &mut adapters);
#[cfg(dx11)]
#[cfg(feature = "dx11")]
self.enumerate(hal::api::Dx11, &self.instance.dx11, &inputs, &mut adapters);
#[cfg(gl)]
#[cfg(feature = "gles")]
self.enumerate(hal::api::Gles, &self.instance.gl, &inputs, &mut adapters);
adapters
@@ -724,7 +724,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.transpose()?;
let mut device_types = Vec::new();
#[cfg(vulkan)]
#[cfg(feature = "vulkan")]
let (id_vulkan, adapters_vk) = gather(
hal::api::Vulkan,
self.instance.vulkan.as_ref(),
@@ -733,7 +733,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
desc.force_fallback_adapter,
&mut device_types,
);
#[cfg(metal)]
#[cfg(feature = "metal")]
let (id_metal, adapters_metal) = gather(
hal::api::Metal,
self.instance.metal.as_ref(),
@@ -742,7 +742,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
desc.force_fallback_adapter,
&mut device_types,
);
#[cfg(dx12)]
#[cfg(feature = "dx12")]
let (id_dx12, adapters_dx12) = gather(
hal::api::Dx12,
self.instance.dx12.as_ref(),
@@ -751,7 +751,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
desc.force_fallback_adapter,
&mut device_types,
);
#[cfg(dx11)]
#[cfg(feature = "dx11")]
let (id_dx11, adapters_dx11) = gather(
hal::api::Dx11,
self.instance.dx11.as_ref(),
@@ -760,7 +760,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
desc.force_fallback_adapter,
&mut device_types,
);
#[cfg(gl)]
#[cfg(feature = "gles")]
let (id_gl, adapters_gl) = gather(
hal::api::Gles,
self.instance.gl.as_ref(),
@@ -813,23 +813,23 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
};
let mut selected = preferred_gpu.unwrap_or(0);
#[cfg(vulkan)]
#[cfg(feature = "vulkan")]
if let Some(id) = self.select(&mut selected, id_vulkan, adapters_vk) {
return Ok(id);
}
#[cfg(metal)]
#[cfg(feature = "metal")]
if let Some(id) = self.select(&mut selected, id_metal, adapters_metal) {
return Ok(id);
}
#[cfg(dx12)]
#[cfg(feature = "dx12")]
if let Some(id) = self.select(&mut selected, id_dx12, adapters_dx12) {
return Ok(id);
}
#[cfg(dx11)]
#[cfg(feature = "dx11")]
if let Some(id) = self.select(&mut selected, id_dx11, adapters_dx11) {
return Ok(id);
}
#[cfg(gl)]
#[cfg(feature = "gles")]
if let Some(id) = self.select(&mut selected, id_gl, adapters_gl) {
return Ok(id);
}
@@ -853,15 +853,15 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let fid = A::hub(self).adapters.prepare(input);
match A::VARIANT {
#[cfg(vulkan)]
#[cfg(feature = "vulkan")]
Backend::Vulkan => fid.assign(Adapter::new(hal_adapter), &mut token).0,
#[cfg(metal)]
#[cfg(feature = "metal")]
Backend::Metal => fid.assign(Adapter::new(hal_adapter), &mut token).0,
#[cfg(dx12)]
#[cfg(feature = "dx12")]
Backend::Dx12 => fid.assign(Adapter::new(hal_adapter), &mut token).0,
#[cfg(dx11)]
#[cfg(feature = "dx11")]
Backend::Dx11 => fid.assign(Adapter::new(hal_adapter), &mut token).0,
#[cfg(gl)]
#[cfg(feature = "gles")]
Backend::Gl => fid.assign(Adapter::new(hal_adapter), &mut token).0,
_ => unreachable!(),
}
+34 -44
View File
@@ -278,26 +278,36 @@ platform supports.";
// evaluated when the macro is used; we've just moved the `#[cfg]` into a macro
// used by `wgpu-core` itself.
/// Define an exported macro named `$public` that expands to a call if the
/// configuration predicate `$condition` is true, or to a panic otherwise.
/// Define an exported macro named `$public` that expands to an expression if
/// the feature `$feature` is enabled, or to a panic otherwise.
///
/// For a call like this:
///
/// define_backend_caller! { name, hidden_name, feature }
///
/// define a macro `name`, used like this:
///
/// name!(expr)
///
/// that expands to `expr` if `feature` is enabled, or a panic otherwise.
///
/// Because of odd technical limitations on exporting macros expanded by other
/// macros, you must supply both a public-facing name for the macro and a
/// private name, which is never used outside this macro. For details:
/// <https://github.com/rust-lang/rust/pull/52234#issuecomment-976702997>
macro_rules! define_backend_caller {
{ $public:ident, $private:ident if $condition:meta } => {
#[cfg( $condition )]
{ $public:ident, $private:ident if $feature:literal } => {
#[cfg(feature = $feature )]
#[macro_export]
macro_rules! $private {
( $backend:literal, $call:expr ) => ( $call )
( $call:expr ) => ( $call )
}
#[cfg(not( $condition ))]
#[cfg(not(feature = $feature ))]
#[macro_export]
macro_rules! $private {
( $backend:literal, $call:expr ) => (
panic!("Unexpected backend {:?}", $backend)
( $call:expr ) => (
panic!("Identifier refers to disabled backend feature {:?}", $feature)
)
}
@@ -306,37 +316,17 @@ macro_rules! define_backend_caller {
}
}
define_backend_caller! {
gfx_if_vulkan, gfx_if_vulkan_hidden
if any(
all(not(target_arch = "wasm32"), not(target_os = "ios"), not(target_os = "macos")),
feature = "vulkan-portability"
)
}
define_backend_caller! {
gfx_if_metal, gfx_if_metal_hidden
if all(not(target_arch = "wasm32"), any(target_os = "ios", target_os = "macos"))
}
define_backend_caller! {
gfx_if_dx12, gfx_if_dx12_hidden
if all(not(target_arch = "wasm32"), windows)
}
define_backend_caller! {
gfx_if_dx11, gfx_if_dx11_hidden
if all(not(target_arch = "wasm32"), windows)
}
define_backend_caller! {
gfx_if_gles, gfx_if_gles_hidden
if any(
all(unix, not(target_os = "macos"), not(target_os = "ios")),
feature = "angle",
target_arch = "wasm32"
)
}
// Define a macro for each `gfx_select!` match arm. For example,
//
// gfx_if_vulkan!(expr)
//
// expands to `expr` if the `"vulkan"` feature is enabled, or to a panic
// otherwise.
define_backend_caller! { gfx_if_vulkan, gfx_if_vulkan_hidden if "vulkan" }
define_backend_caller! { gfx_if_metal, gfx_if_metal_hidden if "metal" }
define_backend_caller! { gfx_if_dx12, gfx_if_dx12_hidden if "dx12" }
define_backend_caller! { gfx_if_dx11, gfx_if_dx11_hidden if "dx11" }
define_backend_caller! { gfx_if_gles, gfx_if_gles_hidden if "gles" }
/// Dispatch on an [`Id`]'s backend to a backend-generic method.
///
@@ -387,11 +377,11 @@ define_backend_caller! {
macro_rules! gfx_select {
($id:expr => $global:ident.$method:ident( $($param:expr),* )) => {
match $id.backend() {
wgt::Backend::Vulkan => $crate::gfx_if_vulkan!("Vulkan", $global.$method::<$crate::api::Vulkan>( $($param),* )),
wgt::Backend::Metal => $crate::gfx_if_metal!("Metal", $global.$method::<$crate::api::Metal>( $($param),* )),
wgt::Backend::Dx12 => $crate::gfx_if_dx12!("Dx12", $global.$method::<$crate::api::Dx12>( $($param),* )),
wgt::Backend::Dx11 => $crate::gfx_if_dx11!("Dx11", $global.$method::<$crate::api::Dx11>( $($param),* )),
wgt::Backend::Gl => $crate::gfx_if_gles!("Gles", $global.$method::<$crate::api::Gles>( $($param),+ )),
wgt::Backend::Vulkan => $crate::gfx_if_vulkan!($global.$method::<$crate::api::Vulkan>( $($param),* )),
wgt::Backend::Metal => $crate::gfx_if_metal!($global.$method::<$crate::api::Metal>( $($param),* )),
wgt::Backend::Dx12 => $crate::gfx_if_dx12!($global.$method::<$crate::api::Dx12>( $($param),* )),
wgt::Backend::Dx11 => $crate::gfx_if_dx11!($global.$method::<$crate::api::Dx11>( $($param),* )),
wgt::Backend::Gl => $crate::gfx_if_gles!($global.$method::<$crate::api::Gles>( $($param),+ )),
other => panic!("Unexpected backend {:?}", other),
}
};
+9
View File
@@ -49,6 +49,15 @@
clippy::pattern_type_mismatch,
)]
#[cfg(not(any(
feature = "dx11",
feature = "dx12",
feature = "gles",
feature = "metal",
feature = "vulkan"
)))]
compile_error!("No back ends enabled in `wgpu-hal`. Enable at least one backend feature.");
#[cfg(all(feature = "metal", not(any(target_os = "macos", target_os = "ios"))))]
compile_error!("Metal API enabled on non-Apple OS. If your project is not using resolver=\"2\" in Cargo.toml, it should.");
#[cfg(all(feature = "dx12", not(windows)))]
+42 -9
View File
@@ -88,20 +88,53 @@ emscripten = ["webgl"]
vulkan-portability = ["wgc/vulkan-portability"]
expose-ids = []
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.wgc]
workspace = true
features = ["raw-window-handle"]
[target.'cfg(target_arch = "wasm32")'.dependencies.wgc]
workspace = true
features = ["raw-window-handle"]
# wgpu-core is always available as an optional dependency, "wgc".
# Whenever wgpu-core is selected, we want the GLES backend and raw
# window handle support.
[dependencies.wgc]
optional = true
workspace = true
features = ["raw-window-handle", "gles"]
# wgpu-core is required whenever not targeting web APIs directly.
# Whenever wgpu-core is selected, we want the GLES backend and raw
# window handle support.
[target.'cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))'.dependencies.wgc]
workspace = true
features = ["raw-window-handle", "gles"]
# We want the wgpu-core Metal backend on macOS and iOS.
# (We should consider also enabling "vulkan" for Vulkan Portability.)
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies.wgc]
workspace = true
features = ["metal"]
# We want the wgpu-core Direct3D backends on Windows.
[target.'cfg(windows)'.dependencies.wgc]
workspace = true
features = ["dx11", "dx12"]
# We want the wgpu-core Vulkan backend on Unix (but not Emscripten) and Windows.
[target.'cfg(any(windows, all(unix, not(target_arch = "emscripten"))))'.dependencies.wgc]
workspace = true
features = ["vulkan"]
[target.'cfg(target_os = "emscripten")'.dependencies.wgc]
workspace = true
features = ["emscripten"]
[dependencies.wgt]
workspace = true
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.hal]
workspace = true
# We need wgpu-hal unless we're targeting the web APIs.
[target.'cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))'.dependencies]
hal = { workspace = true }
[target.'cfg(all(not(target_arch = "wasm32"), unix, not(target_os = "ios"), not(target_os = "macos")))'.dependencies]
hal = { workspace = true, features = ["renderdoc"] }
[target.'cfg(windows)'.dependencies]
hal = { workspace = true, features = ["renderdoc"] }
[target.'cfg(target_arch = "wasm32")'.dependencies.hal]
workspace = true