Skip to content

Commit

Permalink
Remove triage_mapped
Browse files Browse the repository at this point in the history
  • Loading branch information
eliemichel committed Oct 27, 2024
1 parent 4c9371f commit c4f9f46
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 46 deletions.
54 changes: 10 additions & 44 deletions wgpu-core/src/device/life.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Arc<Buffer>>,

/// Resources used by queue submissions still in flight. One entry per
/// submission, with older submissions appearing before younger.
///
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -212,16 +196,20 @@ impl LifetimeTracker {
}

pub(crate) fn map(&mut self, buffer: &Arc<Buffer>) -> Option<SubmissionIndex> {
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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit c4f9f46

Please sign in to comment.