diff --git a/wgpu-core/src/command/bundle.rs b/wgpu-core/src/command/bundle.rs index 5ed7da904..013399392 100644 --- a/wgpu-core/src/command/bundle.rs +++ b/wgpu-core/src/command/bundle.rs @@ -710,14 +710,14 @@ fn set_index_buffer( size: Option, ) -> Result<(), RenderBundleErrorInner> { let buffer = buffer_guard - .get(buffer_id) + .get_owned(buffer_id) .map_err(|_| RenderCommandError::InvalidBufferId(buffer_id))?; state .trackers .buffers .write() - .merge_single(buffer, hal::BufferUses::INDEX)?; + .merge_single(&buffer, hal::BufferUses::INDEX)?; buffer.same_device(&state.device)?; buffer.check_usage(wgt::BufferUsages::INDEX)?; @@ -729,11 +729,11 @@ fn set_index_buffer( state .buffer_memory_init_actions .extend(buffer.initialization_status.read().create_action( - buffer, + &buffer, offset..end, MemoryInitKind::NeedsInitializedMemory, )); - state.set_index_buffer(buffer.clone(), index_format, offset..end); + state.set_index_buffer(buffer, index_format, offset..end); Ok(()) } @@ -755,14 +755,14 @@ fn set_vertex_buffer( } let buffer = buffer_guard - .get(buffer_id) + .get_owned(buffer_id) .map_err(|_| RenderCommandError::InvalidBufferId(buffer_id))?; state .trackers .buffers .write() - .merge_single(buffer, hal::BufferUses::VERTEX)?; + .merge_single(&buffer, hal::BufferUses::VERTEX)?; buffer.same_device(&state.device)?; buffer.check_usage(wgt::BufferUsages::VERTEX)?; @@ -774,11 +774,11 @@ fn set_vertex_buffer( state .buffer_memory_init_actions .extend(buffer.initialization_status.read().create_action( - buffer, + &buffer, offset..end, MemoryInitKind::NeedsInitializedMemory, )); - state.vertex[slot as usize] = Some(VertexState::new(buffer.clone(), offset..end)); + state.vertex[slot as usize] = Some(VertexState::new(buffer, offset..end)); Ok(()) } @@ -897,14 +897,14 @@ fn multi_draw_indirect( let used_bind_groups = pipeline.used_bind_groups; let buffer = buffer_guard - .get(buffer_id) + .get_owned(buffer_id) .map_err(|_| RenderCommandError::InvalidBufferId(buffer_id))?; state .trackers .buffers .write() - .merge_single(buffer, hal::BufferUses::INDIRECT)?; + .merge_single(&buffer, hal::BufferUses::INDIRECT)?; buffer.same_device(&state.device)?; buffer.check_usage(wgt::BufferUsages::INDIRECT)?; @@ -912,7 +912,7 @@ fn multi_draw_indirect( state .buffer_memory_init_actions .extend(buffer.initialization_status.read().create_action( - buffer, + &buffer, offset..(offset + mem::size_of::() as u64), MemoryInitKind::NeedsInitializedMemory, )); @@ -928,7 +928,7 @@ fn multi_draw_indirect( state.flush_vertices(); state.flush_binds(used_bind_groups, dynamic_offsets); state.commands.push(ArcRenderCommand::MultiDrawIndirect { - buffer: buffer.clone(), + buffer, offset, count: None, indexed, diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index 9987d479d..fbd5e1d09 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -430,17 +430,17 @@ impl CommandBuffer { id: id::CommandEncoderId, lock_on_acquire: bool, ) -> Result, CommandEncoderError> { - let storage = hub.command_buffers.read(); - match storage.get(id.into_command_buffer_id()) { + match hub.command_buffers.get(id.into_command_buffer_id()) { Ok(cmd_buf) => { - let mut cmd_buf_data = cmd_buf.data.lock(); - let cmd_buf_data = cmd_buf_data.as_mut().unwrap(); + let mut cmd_buf_data_guard = cmd_buf.data.lock(); + let cmd_buf_data = cmd_buf_data_guard.as_mut().unwrap(); match cmd_buf_data.status { CommandEncoderStatus::Recording => { if lock_on_acquire { cmd_buf_data.status = CommandEncoderStatus::Locked; } - Ok(cmd_buf.clone()) + drop(cmd_buf_data_guard); + Ok(cmd_buf) } CommandEncoderStatus::Locked => { // Any operation on a locked encoder is required to put it into the invalid/error state. diff --git a/wgpu-core/src/device/global.rs b/wgpu-core/src/device/global.rs index 1ab37139b..e0a711b44 100644 --- a/wgpu-core/src/device/global.rs +++ b/wgpu-core/src/device/global.rs @@ -2113,9 +2113,8 @@ impl Global { { let hub = A::hub(self); let surface_guard = self.surfaces.read(); - let device_guard = hub.devices.read(); - let device = match device_guard.get(device_id) { + let device = match hub.devices.get(device_id) { Ok(device) => device, Err(_) => break 'error DeviceError::InvalidDeviceId.into(), }; @@ -2241,7 +2240,7 @@ impl Global { let mut presentation = surface.presentation.lock(); *presentation = Some(present::Presentation { - device: super::any_device::AnyDevice::new(device.clone()), + device: super::any_device::AnyDevice::new(device), config: config.clone(), acquired_texture: None, });