Wgpu: [local] Don't panic if no adapters are found

Created on 31 Oct 2019  路  6Comments  路  Source: gfx-rs/wgpu

It would be nicer not to panic in wgpu_instance_request_adapters.
I don't think it should be a blocker for 0.4, but a nice little thing to have.

good first issue help wanted enhancement

Most helpful comment

@antonok-edm this only fixed a part of the problem in request_adapter. The rest of the problem is in this unwrap

All 6 comments

Unless I misunderstand, this is fixed by 41132a37624e00250ffa2ef8f860af00b86aafbe?

@antonok-edm this only fixed a part of the problem in request_adapter. The rest of the problem is in this unwrap

I tried implementating an fix for wgpu-rs, but the wgpu-native API needs to be extended to cover the following:
(excerpt from wgpu-rs/src/lib.rs)

    /// Retrieves an [`Adapter`] which matches the given options.
    ///
    /// Some options are "soft", so treated as non-mandatory. Others are "hard".
    ///
    /// If no adapters are found that suffice all the "hard" options, `None` is returned.
    pub fn request(options: &wgn::RequestAdapterOptions) -> Option<Self> {
        wgn::request_adapter(/* &*wgn::hub::GLOBAL (private to wgpu-rs) */, &options, &[]).map(|id| Adapter { id })
    }

The problem is that there is no way to access the global wgpu instance.

We need to modify wgpu_instance_request_adapters first, and then consider it's results in wgpu-rs.

I was just taking a look to see if I could fix this since it's marked with good-first-issue. Taking a look in wgpu-native, I see that there is no longer a wgpu_request_adapter function. I'm thinking that it has now been replaced by fn wgpu_request_adapter_async in wgpu-native, which no longer tries to unwrap. Additionally, I see that the Instance::request_adapter fn in wgpu-rs now returns a Future<Output = Option<Adapter>>. If my understanding is right, are there any other changes needed to close this issue?

Yes, sorry, looks like this was fixed at some point recently.
The method is now https://github.com/gfx-rs/wgpu/blob/d45323505c63dc9b5b61c720948f4b20fb0e8a66/wgpu-core/src/instance.rs#L291 and it returns an option.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lordnoriyuki picture lordnoriyuki  路  21Comments

porky11 picture porky11  路  13Comments

cloudhead picture cloudhead  路  15Comments

simast picture simast  路  15Comments

cwfitzgerald picture cwfitzgerald  路  20Comments