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

Remove backend_bits from initialize_adapter_from_env #3904

merged 1 commit into from
Jul 5, 2023

Conversation

fornwall
Copy link
Contributor

@fornwall fornwall commented Jul 3, 2023

Checklist

  • Run cargo clippy.
  • Run cargo clippy --target wasm32-unknown-unknown if applicable.
  • Add change to CHANGELOG.md. See simple instructions inside file.

Connections
#3792, initialize_adapter_from_env_or_default ignores backend_bits if WGPU_ADAPTER_NAME is not set

Description
As described in #3792, the initialize_adapter_from_env_or_default function currently ignores backend_bits if WGPU_ADAPTER_NAME is not set.

Instead of going towards the path of making these utility functions more complex (or adding e.g. backend_bits to RequestAdapterOptions), let's perhaps remove backend_bits from these functions completely, in favour of using InstanceDescriptor::backends? So instead of

let instance = wgpu::Instance::default();
let backends = wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::all);
let adapter = wgpu::util::initialize_adapter_from_env_or_default(&instance, backends, None)

the recommended way would be:

let backends = wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::all);
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { backends, ..Default::default() });
let adapter = wgpu::util::initialize_adapter_from_env_or_default(&instance, None)

What do you think?

Testing
By existing tests, or a utility program such as listed above.

@fornwall fornwall changed the title Remove backends from initialize_adapter_from_env Remove backend_bits from initialize_adapter_from_env Jul 3, 2023
Remove backend_bits from initialize_adapter_from_env, backends can
be specified using the backends field in InstanceDescriptor instead.
Copy link
Member

@Wumpf Wumpf left a comment

Choose a reason for hiding this comment

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

I really like this idea, makes it much simpler. Thanks!

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.

@Wumpf Wumpf merged commit 1c43272 into gfx-rs:trunk Jul 5, 2023
@fornwall fornwall deleted the remove-backend-from-util branch July 5, 2023 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants