diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index c036c9623..0e566c5d7 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -373,8 +373,8 @@ impl Device { self.queue.get().as_ref()?.upgrade() } - pub fn set_queue(&self, queue: Arc>) { - assert!(self.queue.set(Arc::downgrade(&queue)).is_ok()); + pub fn set_queue(&self, queue: &Arc>) { + assert!(self.queue.set(Arc::downgrade(queue)).is_ok()); } /// Check this device for completed commands. diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index 018dcce5e..175baa7d0 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -272,13 +272,14 @@ impl Adapter { } } + #[allow(clippy::type_complexity)] fn create_device_and_queue_from_hal( self: &Arc, hal_device: OpenDevice, desc: &DeviceDescriptor, instance_flags: wgt::InstanceFlags, trace_path: Option<&std::path::Path>, - ) -> Result<(Arc>, Queue), RequestDeviceError> { + ) -> Result<(Arc>, Arc>), RequestDeviceError> { api_log!("Adapter::create_device"); if let Ok(device) = Device::new( @@ -294,17 +295,20 @@ impl Adapter { device: device.clone(), raw: Some(hal_device.queue), }; + let queue = Arc::new(queue); + device.set_queue(&queue); return Ok((device, queue)); } Err(RequestDeviceError::OutOfMemory) } + #[allow(clippy::type_complexity)] fn create_device_and_queue( self: &Arc, desc: &DeviceDescriptor, instance_flags: wgt::InstanceFlags, trace_path: Option<&std::path::Path>, - ) -> Result<(Arc>, Queue), RequestDeviceError> { + ) -> Result<(Arc>, Arc>), RequestDeviceError> { // Verify all features were exposed by the adapter if !self.raw.features.contains(desc.required_features) { return Err(RequestDeviceError::UnsupportedFeature( @@ -1078,17 +1082,13 @@ impl Global { Ok((device, queue)) => (device, queue), Err(e) => break 'error e, }; + let device_id = device_fid.assign(device); resource_log!("Created Device {:?}", device_id); - let device = hub.devices.get(device_id).unwrap(); - - let queue = Arc::new(queue); - let queue_id = queue_fid.assign(queue.clone()); + let queue_id = queue_fid.assign(queue); resource_log!("Created Queue {:?}", queue_id); - device.set_queue(queue); - return (device_id, queue_id, None); }; @@ -1130,17 +1130,13 @@ impl Global { Ok(device) => device, Err(e) => break 'error e, }; + let device_id = devices_fid.assign(device); resource_log!("Created Device {:?}", device_id); - let device = hub.devices.get(device_id).unwrap(); - - let queue = Arc::new(queue); - let queue_id = queues_fid.assign(queue.clone()); + let queue_id = queues_fid.assign(queue); resource_log!("Created Queue {:?}", queue_id); - device.set_queue(queue); - return (device_id, queue_id, None); };