use ManuallyDrop for Device.zero_buffer

This commit is contained in:
teoxoy 2024-08-07 14:43:57 +02:00 committed by Teodor Tanasoaia
parent c1bc0864c5
commit 728b288fda
5 changed files with 11 additions and 9 deletions

View File

@ -263,7 +263,7 @@ impl Global {
encoder, encoder,
&mut tracker.textures, &mut tracker.textures,
&device.alignments, &device.alignments,
device.zero_buffer.as_ref().unwrap(), &device.zero_buffer,
&snatch_guard, &snatch_guard,
) )
} }

View File

@ -155,7 +155,7 @@ pub(crate) fn fixup_discarded_surfaces<
encoder, encoder,
texture_tracker, texture_tracker,
&device.alignments, &device.alignments,
device.zero_buffer.as_ref().unwrap(), &device.zero_buffer,
snatch_guard, snatch_guard,
) )
.unwrap(); .unwrap();
@ -310,7 +310,7 @@ impl<A: HalApi> BakedCommands<A> {
&mut self.encoder, &mut self.encoder,
&mut device_tracker.textures, &mut device_tracker.textures,
&device.alignments, &device.alignments,
device.zero_buffer.as_ref().unwrap(), &device.zero_buffer,
snatch_guard, snatch_guard,
); );

View File

@ -445,7 +445,7 @@ fn handle_texture_init<A: HalApi>(
cmd_buf_raw, cmd_buf_raw,
&mut trackers.textures, &mut trackers.textures,
&device.alignments, &device.alignments,
device.zero_buffer.as_ref().unwrap(), &device.zero_buffer,
snatch_guard, snatch_guard,
)?; )?;
} }

View File

@ -723,7 +723,7 @@ impl Global {
encoder, encoder,
&mut trackers.textures, &mut trackers.textures,
&device.alignments, &device.alignments,
device.zero_buffer.as_ref().unwrap(), &device.zero_buffer,
&device.snatchable_lock.read(), &device.snatchable_lock.read(),
) )
.map_err(QueueWriteError::from)?; .map_err(QueueWriteError::from)?;
@ -990,7 +990,7 @@ impl Global {
encoder, encoder,
&mut trackers.textures, &mut trackers.textures,
&device.alignments, &device.alignments,
device.zero_buffer.as_ref().unwrap(), &device.zero_buffer,
&device.snatchable_lock.read(), &device.snatchable_lock.read(),
) )
.map_err(QueueWriteError::from)?; .map_err(QueueWriteError::from)?;

View File

@ -84,7 +84,7 @@ pub struct Device<A: HalApi> {
pub(crate) adapter: Arc<Adapter<A>>, pub(crate) adapter: Arc<Adapter<A>>,
pub(crate) queue: OnceCell<Weak<Queue<A>>>, pub(crate) queue: OnceCell<Weak<Queue<A>>>,
queue_to_drop: OnceCell<A::Queue>, queue_to_drop: OnceCell<A::Queue>,
pub(crate) zero_buffer: Option<A::Buffer>, pub(crate) zero_buffer: ManuallyDrop<A::Buffer>,
/// The `label` from the descriptor used to create the resource. /// The `label` from the descriptor used to create the resource.
label: String, label: String,
@ -171,12 +171,14 @@ impl<A: HalApi> Drop for Device<A> {
resource_log!("Drop {}", self.error_ident()); resource_log!("Drop {}", self.error_ident());
// SAFETY: We are in the Drop impl and we don't use self.raw anymore after this point. // 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) }; 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. // 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()) }; let pending_writes = unsafe { ManuallyDrop::take(&mut self.pending_writes.lock()) };
pending_writes.dispose(&raw); pending_writes.dispose(&raw);
self.command_allocator.dispose(&raw); self.command_allocator.dispose(&raw);
unsafe { unsafe {
raw.destroy_buffer(self.zero_buffer.take().unwrap()); raw.destroy_buffer(zero_buffer);
raw.destroy_fence(self.fence.write().take().unwrap()); raw.destroy_fence(self.fence.write().take().unwrap());
let queue = self.queue_to_drop.take().unwrap(); let queue = self.queue_to_drop.take().unwrap();
raw.exit(queue); raw.exit(queue);
@ -276,7 +278,7 @@ impl<A: HalApi> Device<A> {
adapter: adapter.clone(), adapter: adapter.clone(),
queue: OnceCell::new(), queue: OnceCell::new(),
queue_to_drop: OnceCell::new(), queue_to_drop: OnceCell::new(),
zero_buffer: Some(zero_buffer), zero_buffer: ManuallyDrop::new(zero_buffer),
label: desc.label.to_string(), label: desc.label.to_string(),
command_allocator, command_allocator,
active_submission_index: AtomicU64::new(0), active_submission_index: AtomicU64::new(0),