Fix failed request for adapter when not available (#31002)

Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com>
This commit is contained in:
Taym Haddadi 2024-01-09 10:12:53 +01:00 committed by GitHub
parent dd0149d953
commit fddc4a430f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 97 additions and 90 deletions

View file

@ -237,35 +237,35 @@ impl GPUAdapterMethods for GPUAdapter {
}
impl AsyncWGPUListener for GPUAdapter {
fn handle_response(&self, response: WebGPUResponseResult, promise: &Rc<Promise>) {
fn handle_response(&self, response: Option<WebGPUResponseResult>, promise: &Rc<Promise>) {
match response {
Ok(WebGPUResponse::RequestDevice {
device_id,
queue_id,
descriptor,
}) => {
let device = GPUDevice::new(
&self.global(),
self.channel.clone(),
&self,
Heap::default(),
descriptor.features,
descriptor.limits,
Some(response) => match response {
Ok(WebGPUResponse::RequestDevice {
device_id,
queue_id,
descriptor.label.unwrap_or_default(),
);
self.global().add_gpu_device(&device);
promise.resolve_native(&device);
},
Err(e) => {
warn!("Could not get GPUDevice({:?})", e);
promise.reject_error(Error::Operation);
},
_ => {
warn!("GPUAdapter received wrong WebGPUResponse");
promise.reject_error(Error::Operation);
descriptor,
}) => {
let device = GPUDevice::new(
&self.global(),
self.channel.clone(),
&self,
Heap::default(),
descriptor.features,
descriptor.limits,
device_id,
queue_id,
descriptor.label.unwrap_or_default(),
);
self.global().add_gpu_device(&device);
promise.resolve_native(&device);
},
Err(e) => {
warn!("Could not get GPUDevice({:?})", e);
promise.reject_error(Error::Operation);
},
Ok(_) => unreachable!("GPUAdapter received wrong WebGPUResponse"),
},
None => unreachable!("Failed to get a response for RequestDevice"),
}
}
}