diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index 5bab6bf4f..9da26c278 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -161,8 +161,9 @@ impl Global { ) { let hub = B::hub(self); let mut token = Token::root(); + let (mut pass_guard, mut token) = hub.compute_passes.write(&mut token); let (buffer_guard, _) = hub.buffers.read(&mut token); - let (mut pass_guard, _) = hub.compute_passes.write(&mut token); + let pass = &mut pass_guard[pass_id]; let (src_buffer, src_pending) = pass.trackers.buffers.use_replace( diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index cc61fb71a..1f5434684 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -383,7 +383,7 @@ impl> Global { ) { let hub = B::hub(self); let mut token = Token::root(); - let (mut pass_guard, _) = hub.render_passes.write(&mut token); + let (mut pass_guard, mut token) = hub.render_passes.write(&mut token); let (buffer_guard, _) = hub.buffers.read(&mut token); let pass = &mut pass_guard[pass_id]; pass.is_ready().unwrap(); @@ -447,7 +447,7 @@ impl> Global { ) { let hub = B::hub(self); let mut token = Token::root(); - let (mut pass_guard, _) = hub.render_passes.write(&mut token); + let (mut pass_guard, mut token) = hub.render_passes.write(&mut token); let (buffer_guard, _) = hub.buffers.read(&mut token); let pass = &mut pass_guard[pass_id]; pass.is_ready().unwrap(); diff --git a/wgpu-core/src/device.rs b/wgpu-core/src/device.rs index 2169ffe03..e5ddab3cb 100644 --- a/wgpu-core/src/device.rs +++ b/wgpu-core/src/device.rs @@ -811,7 +811,7 @@ impl> Global { let hub = B::hub(self); let mut token = Token::root(); - let (device_guard, _) = hub.devices.read(&mut token); + let (device_guard, mut token) = hub.devices.read(&mut token); let device = &device_guard[device_id]; let buffer = device.create_buffer(device_id, desc); let ref_count = buffer.life_guard.ref_count.clone(); @@ -839,7 +839,7 @@ impl> Global { let mut desc = desc.clone(); desc.usage |= resource::BufferUsage::MAP_WRITE; - let (device_guard, _) = hub.devices.read(&mut token); + let (device_guard, mut token) = hub.devices.read(&mut token); let device = &device_guard[device_id]; let mut buffer = device.create_buffer(device_id, &desc); let ref_count = buffer.life_guard.ref_count.clone(); @@ -960,7 +960,7 @@ impl> Global { let hub = B::hub(self); let mut token = Token::root(); - let (device_guard, _) = hub.devices.read(&mut token); + let (device_guard, mut token) = hub.devices.read(&mut token); let device = &device_guard[device_id]; let texture = device.create_texture(device_id, desc); let range = texture.full_range.clone(); @@ -1267,7 +1267,7 @@ impl> Global { let (device_guard, mut token) = hub.devices.read(&mut token); let device = &device_guard[device_id]; - let (bind_group_layout_guard, _) = hub.bind_group_layouts.read(&mut token); + let (bind_group_layout_guard, mut token) = hub.bind_group_layouts.read(&mut token); let bind_group_layout = &bind_group_layout_guard[desc.layout]; let bindings = unsafe { slice::from_raw_parts(desc.bindings, desc.bindings_length as usize) }; @@ -2074,8 +2074,9 @@ impl> Global { impl Global { pub fn device_poll(&self, device_id: DeviceId, force_wait: bool) { let hub = B::hub(self); + let mut token = Token::root(); let callbacks = { - let (device_guard, mut token) = hub.devices.read(&mut Token::root()); + let (device_guard, mut token) = hub.devices.read(&mut token); device_guard[device_id].maintain(self, force_wait, &mut token) }; Device::::fire_map_callbacks(callbacks); @@ -2085,7 +2086,8 @@ impl Global { impl> Global { pub fn device_destroy(&self, device_id: DeviceId) { let hub = B::hub(self); - let (device, mut token) = hub.devices.unregister(device_id, &mut Token::root()); + let mut token = Token::root(); + let (device, mut token) = hub.devices.unregister(device_id, &mut token); device.maintain(self, true, &mut token); device.com_allocator.destroy(&device.raw); } diff --git a/wgpu-core/src/hub.rs b/wgpu-core/src/hub.rs index 8c9dc0f35..909fb1719 100644 --- a/wgpu-core/src/hub.rs +++ b/wgpu-core/src/hub.rs @@ -167,6 +167,7 @@ impl Access> for Root {} impl Access> for Device {} impl Access> for Root {} impl Access> for Device {} +impl Access> for BindGroupLayout {} impl Access> for PipelineLayout {} impl Access> for CommandBuffer {} impl Access> for Root {} @@ -319,17 +320,17 @@ impl Registry { assert!(old.is_none()); } - pub fn read>( - &self, - _token: &mut Token, - ) -> (RwLockReadGuard>, Token) { + pub fn read<'a, A: Access>( + &'a self, + _token: &'a mut Token, + ) -> (RwLockReadGuard<'a, Storage>, Token<'a, T>) { (self.data.read(), Token::new()) } - pub fn write>( - &self, - _token: &mut Token, - ) -> (RwLockWriteGuard>, Token) { + pub fn write<'a, A: Access>( + &'a self, + _token: &'a mut Token, + ) -> (RwLockWriteGuard<'a, Storage>, Token<'a, T>) { (self.data.write(), Token::new()) } } @@ -346,7 +347,11 @@ impl> Registry { id } - pub fn unregister>(&self, id: I, _token: &mut Token) -> (T, Token) { + pub fn unregister<'a, A: Access>( + &self, + id: I, + _token: &'a mut Token, + ) -> (T, Token<'a, T>) { let value = self.data.write().remove(id).unwrap(); //Note: careful about the order here! self.identity.free(id);