Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 1 addition & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion deno_webgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
37 changes: 18 additions & 19 deletions wgpu-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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
Expand Down Expand Up @@ -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 changes: 0 additions & 22 deletions wgpu-core/build.rs

This file was deleted.

10 changes: 5 additions & 5 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading