mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-25 08:13:27 +00:00
don't check if the buffer is still "present" from the user's perspective in LifetimeTracker.handle_mapping
This change doesn't change behavior as `Global.buffer_drop` already unmaps the buffer.
This commit is contained in:
parent
3cc6c2743a
commit
3fba403060
@ -710,7 +710,6 @@ impl<A: HalApi> LifetimeTracker<A> {
|
|||||||
pub(crate) fn handle_mapping(
|
pub(crate) fn handle_mapping(
|
||||||
&mut self,
|
&mut self,
|
||||||
raw: &A::Device,
|
raw: &A::Device,
|
||||||
trackers: &Mutex<Tracker<A>>,
|
|
||||||
snatch_guard: &SnatchGuard,
|
snatch_guard: &SnatchGuard,
|
||||||
) -> Vec<super::BufferMapPendingClosure> {
|
) -> Vec<super::BufferMapPendingClosure> {
|
||||||
if self.ready_to_map.is_empty() {
|
if self.ready_to_map.is_empty() {
|
||||||
@ -721,69 +720,60 @@ impl<A: HalApi> LifetimeTracker<A> {
|
|||||||
|
|
||||||
for buffer in self.ready_to_map.drain(..) {
|
for buffer in self.ready_to_map.drain(..) {
|
||||||
let tracker_index = buffer.tracker_index();
|
let tracker_index = buffer.tracker_index();
|
||||||
let is_removed = {
|
|
||||||
let mut trackers = trackers.lock();
|
// This _cannot_ be inlined into the match. If it is, the lock will be held
|
||||||
trackers.buffers.remove_abandoned(tracker_index)
|
// open through the whole match, resulting in a deadlock when we try to re-lock
|
||||||
|
// the buffer back to active.
|
||||||
|
let mapping = std::mem::replace(
|
||||||
|
&mut *buffer.map_state.lock(),
|
||||||
|
resource::BufferMapState::Idle,
|
||||||
|
);
|
||||||
|
let pending_mapping = match mapping {
|
||||||
|
resource::BufferMapState::Waiting(pending_mapping) => pending_mapping,
|
||||||
|
// Mapping cancelled
|
||||||
|
resource::BufferMapState::Idle => continue,
|
||||||
|
// Mapping queued at least twice by map -> unmap -> map
|
||||||
|
// and was already successfully mapped below
|
||||||
|
resource::BufferMapState::Active { .. } => {
|
||||||
|
*buffer.map_state.lock() = mapping;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
_ => panic!("No pending mapping."),
|
||||||
};
|
};
|
||||||
if is_removed {
|
let status = if pending_mapping.range.start != pending_mapping.range.end {
|
||||||
*buffer.map_state.lock() = resource::BufferMapState::Idle;
|
log::debug!("Buffer {tracker_index:?} map state -> Active");
|
||||||
log::trace!("Buffer ready to map {tracker_index:?} is not tracked anymore");
|
let host = pending_mapping.op.host;
|
||||||
|
let size = pending_mapping.range.end - pending_mapping.range.start;
|
||||||
|
match super::map_buffer(
|
||||||
|
raw,
|
||||||
|
&buffer,
|
||||||
|
pending_mapping.range.start,
|
||||||
|
size,
|
||||||
|
host,
|
||||||
|
snatch_guard,
|
||||||
|
) {
|
||||||
|
Ok(ptr) => {
|
||||||
|
*buffer.map_state.lock() = resource::BufferMapState::Active {
|
||||||
|
ptr,
|
||||||
|
range: pending_mapping.range.start..pending_mapping.range.start + size,
|
||||||
|
host,
|
||||||
|
};
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("Mapping failed: {e}");
|
||||||
|
Err(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// This _cannot_ be inlined into the match. If it is, the lock will be held
|
*buffer.map_state.lock() = resource::BufferMapState::Active {
|
||||||
// open through the whole match, resulting in a deadlock when we try to re-lock
|
ptr: std::ptr::NonNull::dangling(),
|
||||||
// the buffer back to active.
|
range: pending_mapping.range,
|
||||||
let mapping = std::mem::replace(
|
host: pending_mapping.op.host,
|
||||||
&mut *buffer.map_state.lock(),
|
|
||||||
resource::BufferMapState::Idle,
|
|
||||||
);
|
|
||||||
let pending_mapping = match mapping {
|
|
||||||
resource::BufferMapState::Waiting(pending_mapping) => pending_mapping,
|
|
||||||
// Mapping cancelled
|
|
||||||
resource::BufferMapState::Idle => continue,
|
|
||||||
// Mapping queued at least twice by map -> unmap -> map
|
|
||||||
// and was already successfully mapped below
|
|
||||||
resource::BufferMapState::Active { .. } => {
|
|
||||||
*buffer.map_state.lock() = mapping;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
_ => panic!("No pending mapping."),
|
|
||||||
};
|
};
|
||||||
let status = if pending_mapping.range.start != pending_mapping.range.end {
|
Ok(())
|
||||||
log::debug!("Buffer {tracker_index:?} map state -> Active");
|
};
|
||||||
let host = pending_mapping.op.host;
|
pending_callbacks.push((pending_mapping.op, status));
|
||||||
let size = pending_mapping.range.end - pending_mapping.range.start;
|
|
||||||
match super::map_buffer(
|
|
||||||
raw,
|
|
||||||
&buffer,
|
|
||||||
pending_mapping.range.start,
|
|
||||||
size,
|
|
||||||
host,
|
|
||||||
snatch_guard,
|
|
||||||
) {
|
|
||||||
Ok(ptr) => {
|
|
||||||
*buffer.map_state.lock() = resource::BufferMapState::Active {
|
|
||||||
ptr,
|
|
||||||
range: pending_mapping.range.start
|
|
||||||
..pending_mapping.range.start + size,
|
|
||||||
host,
|
|
||||||
};
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
log::error!("Mapping failed: {e}");
|
|
||||||
Err(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
*buffer.map_state.lock() = resource::BufferMapState::Active {
|
|
||||||
ptr: std::ptr::NonNull::dangling(),
|
|
||||||
range: pending_mapping.range,
|
|
||||||
host: pending_mapping.op.host,
|
|
||||||
};
|
|
||||||
Ok(())
|
|
||||||
};
|
|
||||||
pending_callbacks.push((pending_mapping.op, status));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pending_callbacks
|
pending_callbacks
|
||||||
}
|
}
|
||||||
|
@ -430,8 +430,7 @@ impl<A: HalApi> Device<A> {
|
|||||||
|
|
||||||
life_tracker.triage_mapped();
|
life_tracker.triage_mapped();
|
||||||
|
|
||||||
let mapping_closures =
|
let mapping_closures = life_tracker.handle_mapping(self.raw(), &snatch_guard);
|
||||||
life_tracker.handle_mapping(self.raw(), &self.trackers, &snatch_guard);
|
|
||||||
|
|
||||||
let queue_empty = life_tracker.queue_empty();
|
let queue_empty = life_tracker.queue_empty();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user