From c4f9f46b3fb3b2d7b59f96fe9148f24405430c7f Mon Sep 17 00:00:00 2001 From: Elie Michel Date: Sun, 27 Oct 2024 09:42:19 +0100 Subject: [PATCH] Remove triage_mapped --- wgpu-core/src/device/life.rs | 54 ++++++-------------------------- wgpu-core/src/device/resource.rs | 2 -- 2 files changed, 10 insertions(+), 46 deletions(-) diff --git a/wgpu-core/src/device/life.rs b/wgpu-core/src/device/life.rs index bc66a4d1b9..47e33ab11f 100644 --- a/wgpu-core/src/device/life.rs +++ b/wgpu-core/src/device/life.rs @@ -126,35 +126,20 @@ pub enum WaitIdleError { /// - Each buffer's `ResourceInfo::submission_index` records the index of the /// most recent queue submission that uses that buffer. /// -/// - Calling `Global::buffer_map_async` adds the buffer to -/// `self.mapped`, and changes `Buffer::map_state` to prevent it -/// from being used in any new submissions. -/// /// - When the device is polled, the following `LifetimeTracker` methods decide /// what should happen next: /// -/// 1) `triage_mapped` drains `self.mapped`, checking the submission index -/// of each buffer against the queue submissions that have finished -/// execution. Buffers used by submissions still in flight go in -/// `self.active[index].mapped`, and the rest go into -/// `self.ready_to_map`. -/// -/// 2) `triage_submissions` moves entries in `self.active[i]` for completed +/// 1) `triage_submissions` moves entries in `self.active[i]` for completed /// submissions to `self.ready_to_map`. At this point, both /// `self.active` and `self.ready_to_map` are up to date with the given /// submission index. /// -/// 3) `handle_mapping` drains `self.ready_to_map` and actually maps the +/// 2) `handle_mapping` drains `self.ready_to_map` and actually maps the /// buffers, collecting a list of notification closures to call. /// /// Only calling `Global::buffer_map_async` clones a new `Arc` for the /// buffer. This new `Arc` is only dropped by `handle_mapping`. pub(crate) struct LifetimeTracker { - /// Buffers for which a call to [`Buffer::map_async`] has succeeded, but - /// which haven't been examined by `triage_mapped` yet to decide when they - /// can be mapped. - mapped: Vec>, - /// Resources used by queue submissions still in flight. One entry per /// submission, with older submissions appearing before younger. /// @@ -182,7 +167,6 @@ pub(crate) struct LifetimeTracker { impl LifetimeTracker { pub fn new() -> Self { Self { - mapped: Vec::new(), active: Vec::new(), ready_to_map: Vec::new(), work_done_closures: SmallVec::new(), @@ -212,16 +196,20 @@ impl LifetimeTracker { } pub(crate) fn map(&mut self, buffer: &Arc) -> Option { - self.mapped.push(buffer.clone()); - - // Warning: this duplicates what is in triage_mapped() + // Determine which buffers are ready to map, and which must wait for the GPU. let submission = self .active .iter_mut() .rev() .find(|a| a.contains_buffer(&buffer)); - submission.map(|s| s.index) + let maybe_submission_index = submission.as_ref().map(|s| s.index.clone()); + + submission + .map_or(&mut self.ready_to_map, |a| &mut a.mapped) + .push(buffer.clone()); + + maybe_submission_index } /// Returns the submission index of the most recent submission that uses the @@ -331,28 +319,6 @@ impl LifetimeTracker { } } - /// Determine which buffers are ready to map, and which must wait for the - /// GPU. - /// - /// See the documentation for [`LifetimeTracker`] for details. - pub(crate) fn triage_mapped(&mut self) { - if self.mapped.is_empty() { - return; - } - - for buffer in self.mapped.drain(..) { - let submission = self - .active - .iter_mut() - .rev() - .find(|a| a.contains_buffer(&buffer)); - - submission - .map_or(&mut self.ready_to_map, |a| &mut a.mapped) - .push(buffer); - } - } - /// Map the buffers in `self.ready_to_map`. /// /// Return a list of mapping notifications to send. diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index 21ecf85d24..46271f7ac9 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -493,8 +493,6 @@ impl Device { let submission_closures = life_tracker.triage_submissions(submission_index, &self.command_allocator); - life_tracker.triage_mapped(); - let mapping_closures = life_tracker.handle_mapping(self.raw(), &snatch_guard); let queue_empty = life_tracker.queue_empty();