diff --git a/wgpu-core/src/command/clear.rs b/wgpu-core/src/command/clear.rs index 6f51f73d5..f261e61d4 100644 --- a/wgpu-core/src/command/clear.rs +++ b/wgpu-core/src/command/clear.rs @@ -263,7 +263,7 @@ impl Global { encoder, &mut tracker.textures, &device.alignments, - device.zero_buffer.as_ref().unwrap(), + &device.zero_buffer, &snatch_guard, ) } diff --git a/wgpu-core/src/command/memory_init.rs b/wgpu-core/src/command/memory_init.rs index 895901d92..96427eacc 100644 --- a/wgpu-core/src/command/memory_init.rs +++ b/wgpu-core/src/command/memory_init.rs @@ -155,7 +155,7 @@ pub(crate) fn fixup_discarded_surfaces< encoder, texture_tracker, &device.alignments, - device.zero_buffer.as_ref().unwrap(), + &device.zero_buffer, snatch_guard, ) .unwrap(); @@ -310,7 +310,7 @@ impl BakedCommands { &mut self.encoder, &mut device_tracker.textures, &device.alignments, - device.zero_buffer.as_ref().unwrap(), + &device.zero_buffer, snatch_guard, ); diff --git a/wgpu-core/src/command/transfer.rs b/wgpu-core/src/command/transfer.rs index 0e4c21f99..b8208f5dd 100644 --- a/wgpu-core/src/command/transfer.rs +++ b/wgpu-core/src/command/transfer.rs @@ -445,7 +445,7 @@ fn handle_texture_init( cmd_buf_raw, &mut trackers.textures, &device.alignments, - device.zero_buffer.as_ref().unwrap(), + &device.zero_buffer, snatch_guard, )?; } diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index 1b562d560..2c564d6ee 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -723,7 +723,7 @@ impl Global { encoder, &mut trackers.textures, &device.alignments, - device.zero_buffer.as_ref().unwrap(), + &device.zero_buffer, &device.snatchable_lock.read(), ) .map_err(QueueWriteError::from)?; @@ -990,7 +990,7 @@ impl Global { encoder, &mut trackers.textures, &device.alignments, - device.zero_buffer.as_ref().unwrap(), + &device.zero_buffer, &device.snatchable_lock.read(), ) .map_err(QueueWriteError::from)?; diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index 63c09831d..667bb9ee5 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -84,7 +84,7 @@ pub struct Device { pub(crate) adapter: Arc>, pub(crate) queue: OnceCell>>, queue_to_drop: OnceCell, - pub(crate) zero_buffer: Option, + pub(crate) zero_buffer: ManuallyDrop, /// The `label` from the descriptor used to create the resource. label: String, @@ -171,12 +171,14 @@ impl Drop for Device { resource_log!("Drop {}", self.error_ident()); // SAFETY: We are in the Drop impl and we don't use self.raw anymore after this point. let raw = unsafe { ManuallyDrop::take(&mut self.raw) }; + // SAFETY: We are in the Drop impl and we don't use self.zero_buffer anymore after this point. + let zero_buffer = unsafe { ManuallyDrop::take(&mut self.zero_buffer) }; // SAFETY: We are in the Drop impl and we don't use self.pending_writes anymore after this point. let pending_writes = unsafe { ManuallyDrop::take(&mut self.pending_writes.lock()) }; pending_writes.dispose(&raw); self.command_allocator.dispose(&raw); unsafe { - raw.destroy_buffer(self.zero_buffer.take().unwrap()); + raw.destroy_buffer(zero_buffer); raw.destroy_fence(self.fence.write().take().unwrap()); let queue = self.queue_to_drop.take().unwrap(); raw.exit(queue); @@ -276,7 +278,7 @@ impl Device { adapter: adapter.clone(), queue: OnceCell::new(), queue_to_drop: OnceCell::new(), - zero_buffer: Some(zero_buffer), + zero_buffer: ManuallyDrop::new(zero_buffer), label: desc.label.to_string(), command_allocator, active_submission_index: AtomicU64::new(0),