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

Remove backend_bits from initialize_adapter_from_env #3904

Merged
merged 1 commit into from
Jul 5, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Bottom level categories:
#### Misc Breaking Changes

- Change `AdapterInfo::{device,vendor}` to be `u32` instead of `usize`. By @ameknite in [#3760](https://github.com/gfx-rs/wgpu/pull/3760)
- Remove the `backend_bits` parameter in `initialize_adapter_from_env` and `initialize_adapter_from_env_or_default` - use [InstanceDescriptor::backends](https://docs.rs/wgpu/latest/wgpu/struct.InstanceDescriptor.html#structfield.backends) instead. By @fornwall in [#3904](https://github.com/gfx-rs/wgpu/pull/3904)

#### DX12

Expand Down
7 changes: 3 additions & 4 deletions examples/common/src/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,9 @@ async fn setup<E: Example>(title: &str) -> Setup {

(size, surface)
};
let adapter =
wgpu::util::initialize_adapter_from_env_or_default(&instance, backends, Some(&surface))
.await
.expect("No suitable GPU adapters found on the system!");
let adapter = wgpu::util::initialize_adapter_from_env_or_default(&instance, Some(&surface))
.await
.expect("No suitable GPU adapters found on the system!");

#[cfg(not(target_arch = "wasm32"))]
{
Expand Down
1 change: 0 additions & 1 deletion tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ fn initialize_adapter() -> (Adapter, SurfaceGuard) {
let compatible_surface: Option<&Surface> = compatible_surface.as_ref();
let adapter = pollster::block_on(wgpu::util::initialize_adapter_from_env_or_default(
&instance,
backends,
compatible_surface,
))
.expect("could not find suitable adapter on the system");
Expand Down
12 changes: 4 additions & 8 deletions wgpu/src/util/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ pub fn power_preference_from_env() -> Option<PowerPreference> {

/// Initialize the adapter obeying the WGPU_ADAPTER_NAME environment variable.
#[cfg(not(target_arch = "wasm32"))]
pub fn initialize_adapter_from_env(instance: &Instance, backend_bits: Backends) -> Option<Adapter> {
pub fn initialize_adapter_from_env(instance: &Instance) -> Option<Adapter> {
let desired_adapter_name = std::env::var("WGPU_ADAPTER_NAME")
.as_deref()
.map(str::to_lowercase)
.ok()?;

let adapters = instance.enumerate_adapters(backend_bits);
let adapters = instance.enumerate_adapters(Backends::all());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it took me really long to understand that enumerate_adapter does in fact not list backends that it didn't know about at creation. Should really be explicit on on its doc string I suppose.


let mut chosen_adapter = None;
for adapter in adapters {
Expand All @@ -60,20 +60,16 @@ pub fn initialize_adapter_from_env(instance: &Instance, backend_bits: Backends)

/// Initialize the adapter obeying the WGPU_ADAPTER_NAME environment variable.
#[cfg(target_arch = "wasm32")]
pub fn initialize_adapter_from_env(
_instance: &Instance,
_backend_bits: Backends,
) -> Option<Adapter> {
pub fn initialize_adapter_from_env(_instance: &Instance) -> Option<Adapter> {
None
}

/// Initialize the adapter obeying the WGPU_ADAPTER_NAME environment variable and if it doesn't exist fall back on a default adapter.
pub async fn initialize_adapter_from_env_or_default(
instance: &Instance,
backend_bits: wgt::Backends,
compatible_surface: Option<&Surface>,
) -> Option<Adapter> {
match initialize_adapter_from_env(instance, backend_bits) {
match initialize_adapter_from_env(instance) {
Some(a) => Some(a),
None => {
instance
Expand Down