diff --git a/deno_webgpu/lib.rs b/deno_webgpu/lib.rs index c64cb4a06..b20b39d5b 100644 --- a/deno_webgpu/lib.rs +++ b/deno_webgpu/lib.rs @@ -649,7 +649,7 @@ pub fn op_webgpu_request_device( memory_hints: wgpu_types::MemoryHints::default(), }; - let (device, queue, maybe_err) = instance.adapter_request_device( + let res = instance.adapter_request_device( adapter, &descriptor, std::env::var("DENO_WEBGPU_TRACE") @@ -660,9 +660,8 @@ pub fn op_webgpu_request_device( None, ); adapter_resource.close(); - if let Some(err) = maybe_err { - return Err(DomExceptionOperationError::new(&err.to_string()).into()); - } + + let (device, queue) = res.map_err(|err| DomExceptionOperationError::new(&err.to_string()))?; let device_features = instance.device_features(device)?; let features = deserialize_features(&device_features); diff --git a/player/src/bin/play.rs b/player/src/bin/play.rs index f0198f130..eb26ce6ba 100644 --- a/player/src/bin/play.rs +++ b/player/src/bin/play.rs @@ -82,14 +82,14 @@ fn main() { log::info!("Picked '{}'", info.name); let device_id = wgc::id::Id::zip(1, 0, backend); let queue_id = wgc::id::Id::zip(1, 0, backend); - let (_, _, error) = global.adapter_request_device( + let res = global.adapter_request_device( adapter, &desc, None, Some(device_id), Some(queue_id), ); - if let Some(e) = error { + if let Err(e) = res { panic!("{:?}", e); } (device_id, queue_id) diff --git a/player/tests/test.rs b/player/tests/test.rs index 653a6fc9b..3b26a202d 100644 --- a/player/tests/test.rs +++ b/player/tests/test.rs @@ -108,7 +108,7 @@ impl Test<'_> { let backend = adapter.backend(); let device_id = wgc::id::Id::zip(test_num, 0, backend); let queue_id = wgc::id::Id::zip(test_num, 0, backend); - let (_, _, error) = global.adapter_request_device( + let res = global.adapter_request_device( adapter, &wgt::DeviceDescriptor { label: None, @@ -120,7 +120,7 @@ impl Test<'_> { Some(device_id), Some(queue_id), ); - if let Some(e) = error { + if let Err(e) = res { panic!("{:?}", e); } diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index db4c19282..865ae6e3d 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -899,7 +899,7 @@ impl Global { trace_path: Option<&std::path::Path>, device_id_in: Option, queue_id_in: Option, - ) -> (DeviceId, QueueId, Option) { + ) -> Result<(DeviceId, QueueId), RequestDeviceError> { profiling::scope!("Adapter::request_device"); api_log!("Adapter::request_device"); @@ -907,26 +907,17 @@ impl Global { let device_fid = self.hub.devices.prepare(backend, device_id_in); let queue_fid = self.hub.queues.prepare(backend, queue_id_in); - let error = 'error: { - let adapter = self.hub.adapters.strict_get(adapter_id); - let (device, queue) = - match adapter.create_device_and_queue(desc, self.instance.flags, trace_path) { - Ok((device, queue)) => (device, queue), - Err(e) => break 'error e, - }; + let adapter = self.hub.adapters.strict_get(adapter_id); + let (device, queue) = + adapter.create_device_and_queue(desc, self.instance.flags, trace_path)?; - let device_id = device_fid.assign(device); - resource_log!("Created Device {:?}", device_id); + let device_id = device_fid.assign(device); + resource_log!("Created Device {:?}", device_id); - let queue_id = queue_fid.assign(queue); - resource_log!("Created Queue {:?}", queue_id); + let queue_id = queue_fid.assign(queue); + resource_log!("Created Queue {:?}", queue_id); - return (device_id, queue_id, None); - }; - - let device_id = device_fid.assign_error(); - let queue_id = queue_fid.assign_error(); - (device_id, queue_id, Some(error)) + Ok((device_id, queue_id)) } /// # Safety @@ -941,37 +932,28 @@ impl Global { trace_path: Option<&std::path::Path>, device_id_in: Option, queue_id_in: Option, - ) -> (DeviceId, QueueId, Option) { + ) -> Result<(DeviceId, QueueId), RequestDeviceError> { profiling::scope!("Global::create_device_from_hal"); let backend = adapter_id.backend(); let devices_fid = self.hub.devices.prepare(backend, device_id_in); let queues_fid = self.hub.queues.prepare(backend, queue_id_in); - let error = 'error: { - let adapter = self.hub.adapters.strict_get(adapter_id); - let (device, queue) = match adapter.create_device_and_queue_from_hal( - hal_device, - desc, - self.instance.flags, - trace_path, - ) { - Ok(device) => device, - Err(e) => break 'error e, - }; + let adapter = self.hub.adapters.strict_get(adapter_id); + let (device, queue) = adapter.create_device_and_queue_from_hal( + hal_device, + desc, + self.instance.flags, + trace_path, + )?; - let device_id = devices_fid.assign(device); - resource_log!("Created Device {:?}", device_id); + let device_id = devices_fid.assign(device); + resource_log!("Created Device {:?}", device_id); - let queue_id = queues_fid.assign(queue); - resource_log!("Created Queue {:?}", queue_id); + let queue_id = queues_fid.assign(queue); + resource_log!("Created Queue {:?}", queue_id); - return (device_id, queue_id, None); - }; - - let device_id = devices_fid.assign_error(); - let queue_id = queues_fid.assign_error(); - (device_id, queue_id, Some(error)) + Ok((device_id, queue_id)) } } diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs index 77616cdeb..dac5d40e4 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -108,7 +108,7 @@ impl ContextWgpuCore { if trace_dir.is_some() { log::error!("Feature 'trace' has been removed temporarily, see https://github.com/gfx-rs/wgpu/issues/5974"); } - let (device_id, queue_id, error) = unsafe { + let (device_id, queue_id) = unsafe { self.0.create_device_from_hal( *adapter, hal_device.into(), @@ -117,10 +117,7 @@ impl ContextWgpuCore { None, None, ) - }; - if let Some(err) = error { - self.handle_error_fatal(err, "Adapter::create_device_from_hal"); - } + }?; let error_sink = Arc::new(Mutex::new(ErrorSinkRaw::new())); let device = Device { id: device_id, @@ -606,16 +603,19 @@ impl crate::Context for ContextWgpuCore { if trace_dir.is_some() { log::error!("Feature 'trace' has been removed temporarily, see https://github.com/gfx-rs/wgpu/issues/5974"); } - let (device_id, queue_id, error) = self.0.adapter_request_device( + let res = self.0.adapter_request_device( *adapter_data, &desc.map_label(|l| l.map(Borrowed)), None, None, None, ); - if let Some(err) = error { - return ready(Err(err.into())); - } + let (device_id, queue_id) = match res { + Ok(ids) => ids, + Err(err) => { + return ready(Err(err.into())); + } + }; let error_sink = Arc::new(Mutex::new(ErrorSinkRaw::new())); let device = Device { id: device_id,