Less nesting in webgpu response (#32799)

* Remove Option wrap of WebGPUResponse

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* Replace WebGPUResponseResult with WebGPUResponse

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
Samson 2024-07-17 22:37:52 +02:00 committed by GitHub
parent 1223335547
commit 34eed29037
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 196 additions and 214 deletions

View file

@ -7,7 +7,7 @@ use std::rc::Rc;
use dom_struct::dom_struct;
use js::jsapi::{Heap, JSObject};
use webgpu::{wgt, WebGPU, WebGPUAdapter, WebGPURequest, WebGPUResponse, WebGPUResponseResult};
use webgpu::{wgt, WebGPU, WebGPUAdapter, WebGPURequest, WebGPUResponse};
use super::gpusupportedfeatures::GPUSupportedFeatures;
use super::types::{GPUAdapterInfo, GPUSupportedLimits};
@ -263,35 +263,30 @@ impl GPUAdapterMethods for GPUAdapter {
}
impl AsyncWGPUListener for GPUAdapter {
fn handle_response(&self, response: Option<WebGPUResponseResult>, promise: &Rc<Promise>) {
fn handle_response(&self, response: WebGPUResponse, promise: &Rc<Promise>) {
match response {
Some(response) => match response {
Ok(WebGPUResponse::RequestDevice {
device_id,
queue_id,
descriptor,
}) => {
let device = GPUDevice::new(
&self.global(),
self.channel.clone(),
self,
Heap::default(),
descriptor.required_features,
descriptor.required_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"),
WebGPUResponse::Device(Ok(device)) => {
let descriptor = device.descriptor;
let device = GPUDevice::new(
&self.global(),
self.channel.clone(),
self,
Heap::default(),
descriptor.required_features,
descriptor.required_limits,
device.device_id,
device.queue_id,
descriptor.label.unwrap_or_default(),
);
self.global().add_gpu_device(&device);
promise.resolve_native(&device);
},
None => unreachable!("Failed to get a response for RequestDevice"),
WebGPUResponse::Device(Err(e)) => {
warn!("Could not get GPUDevice({:?})", e);
promise.reject_error(Error::Operation);
},
WebGPUResponse::None => unreachable!("Failed to get a response for RequestDevice"),
_ => unreachable!("GPUAdapter received wrong WebGPUResponse"),
}
}
}