From 3cc6c2743a95fa60a6bf7c60e61f5e90b0c283f6 Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Thu, 4 Jul 2024 17:14:39 +0200 Subject: [PATCH] remove `LifetimeTracker.future_suspected_{buffers,textures}` --- wgpu-core/src/device/global.rs | 46 ++++++++-------------------------- wgpu-core/src/device/life.rs | 22 ---------------- wgpu-core/src/device/queue.rs | 25 +++++++++++++----- 3 files changed, 30 insertions(+), 63 deletions(-) diff --git a/wgpu-core/src/device/global.rs b/wgpu-core/src/device/global.rs index f2b875030..2faefd914 100644 --- a/wgpu-core/src/device/global.rs +++ b/wgpu-core/src/device/global.rs @@ -433,21 +433,11 @@ impl Global { let device = buffer.device.clone(); - if device - .pending_writes - .lock() - .as_ref() - .unwrap() - .contains_buffer(&buffer) - { - device.lock_life().future_suspected_buffers.push(buffer); - } else { - device - .lock_life() - .suspected_resources - .buffers - .insert(buffer.tracker_index(), buffer); - } + device + .lock_life() + .suspected_resources + .buffers + .insert(buffer.tracker_index(), buffer); if wait { match device.wait_for_submit(last_submit_index) { @@ -626,26 +616,12 @@ impl Global { let last_submit_index = texture.submission_index(); let device = &texture.device; - { - if device - .pending_writes - .lock() - .as_ref() - .unwrap() - .contains_texture(&texture) - { - device - .lock_life() - .future_suspected_textures - .push(texture.clone()); - } else { - device - .lock_life() - .suspected_resources - .textures - .insert(texture.tracker_index(), texture.clone()); - } - } + + device + .lock_life() + .suspected_resources + .textures + .insert(texture.tracker_index(), texture.clone()); if wait { match device.wait_for_submit(last_submit_index) { diff --git a/wgpu-core/src/device/life.rs b/wgpu-core/src/device/life.rs index 5fca35626..d7091d2a1 100644 --- a/wgpu-core/src/device/life.rs +++ b/wgpu-core/src/device/life.rs @@ -230,13 +230,6 @@ pub(crate) struct LifetimeTracker { /// queue submissions still in flight. mapped: Vec>>, - /// Buffers can be used in a submission that is yet to be made, by the - /// means of `write_buffer()`, so we have a special place for them. - pub future_suspected_buffers: Vec>>, - - /// Textures can be used in the upcoming submission by `write_texture`. - pub future_suspected_textures: Vec>>, - /// Resources whose user handle has died (i.e. drop/destroy has been called) /// and will likely be ready for destruction soon. pub suspected_resources: ResourceMaps, @@ -269,8 +262,6 @@ impl LifetimeTracker { pub fn new() -> Self { Self { mapped: Vec::new(), - future_suspected_buffers: Vec::new(), - future_suspected_textures: Vec::new(), suspected_resources: ResourceMaps::new(), active: Vec::new(), ready_to_map: Vec::new(), @@ -301,19 +292,6 @@ impl LifetimeTracker { }); } - pub fn post_submit(&mut self) { - for v in self.future_suspected_buffers.drain(..) { - self.suspected_resources - .buffers - .insert(v.tracker_index(), v); - } - for v in self.future_suspected_textures.drain(..) { - self.suspected_resources - .textures - .insert(v.tracker_index(), v); - } - } - pub(crate) fn map(&mut self, value: &Arc>) { self.mapped.push(value.clone()); } diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index afce7ed4f..75407744d 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -149,6 +149,11 @@ pub(crate) struct EncoderInFlight { raw: A::CommandEncoder, cmd_buffers: Vec, trackers: Tracker, + + /// These are the buffers that have been tracked by `PendingWrites`. + pending_buffers: Vec>>, + /// These are the textures that have been tracked by `PendingWrites`. + pending_textures: Vec>>, } impl EncoderInFlight { @@ -163,6 +168,8 @@ impl EncoderInFlight { // resources, so can be _very_ expensive. profiling::scope!("drop command buffer trackers"); drop(self.trackers); + drop(self.pending_buffers); + drop(self.pending_textures); } self.raw } @@ -259,20 +266,26 @@ impl PendingWrites { device: &A::Device, queue: &A::Queue, ) -> Result>, DeviceError> { - self.dst_buffers.clear(); - self.dst_textures.clear(); if self.is_recording { + let pending_buffers = self.dst_buffers.drain().map(|(_, b)| b).collect(); + let pending_textures = self.dst_textures.drain().map(|(_, t)| t).collect(); + let cmd_buf = unsafe { self.command_encoder.end_encoding()? }; self.is_recording = false; let new_encoder = command_allocator.acquire_encoder(device, queue)?; - Ok(Some(EncoderInFlight { + let encoder = EncoderInFlight { raw: mem::replace(&mut self.command_encoder, new_encoder), cmd_buffers: vec![cmd_buf], trackers: Tracker::new(), - })) + pending_buffers, + pending_textures, + }; + Ok(Some(encoder)) } else { + self.dst_buffers.clear(); + self.dst_textures.clear(); Ok(None) } } @@ -1352,6 +1365,8 @@ impl Global { raw: baked.encoder, cmd_buffers: baked.list, trackers: baked.trackers, + pending_buffers: Vec::new(), + pending_textures: Vec::new(), }); } @@ -1467,8 +1482,6 @@ impl Global { Err(WaitIdleError::WrongSubmissionIndex(..)) => unreachable!(), }; - device.lock_life().post_submit(); - (submit_index, closures) };