remove Buffer.sync_mapped_writes

`zero_init_needs_flush_now` was always equal to `mapping.is_coherent`
which is not correct but is fixed by the next commit.
This commit is contained in:
teoxoy 2024-08-07 16:42:43 +02:00 committed by Erich Gubler
parent 5617f0fd17
commit f0875e8fda
4 changed files with 5 additions and 15 deletions

View File

@ -314,14 +314,11 @@ fn map_buffer<A: HalApi>(
.map_err(DeviceError::from)?
};
*buffer.sync_mapped_writes.lock() = match kind {
HostMap::Read if !mapping.is_coherent => unsafe {
if !mapping.is_coherent && kind == HostMap::Read {
unsafe {
raw.invalidate_mapped_ranges(raw_buffer, iter::once(offset..offset + size));
None
},
HostMap::Write if !mapping.is_coherent => Some(offset..offset + size),
_ => None,
};
}
}
assert_eq!(offset % wgt::COPY_BUFFER_ALIGNMENT, 0);
assert_eq!(size % wgt::COPY_BUFFER_ALIGNMENT, 0);
@ -339,9 +336,6 @@ fn map_buffer<A: HalApi>(
// If this is a write mapping zeroing out the memory here is the only
// reasonable way as all data is pushed to GPU anyways.
// No need to flush if it is flushed later anyways.
let zero_init_needs_flush_now =
mapping.is_coherent && buffer.sync_mapped_writes.lock().is_none();
let mapped = unsafe { std::slice::from_raw_parts_mut(mapping.ptr.as_ptr(), size as usize) };
for uninitialized in buffer
@ -355,7 +349,7 @@ fn map_buffer<A: HalApi>(
(uninitialized.start - offset) as usize..(uninitialized.end - offset) as usize;
mapped[fill_range].fill(0);
if zero_init_needs_flush_now {
if mapping.is_coherent {
unsafe { raw.flush_mapped_ranges(raw_buffer, iter::once(uninitialized)) };
}
}

View File

@ -597,7 +597,6 @@ impl<A: HalApi> Device<A> {
rank::BUFFER_INITIALIZATION_STATUS,
BufferInitTracker::new(aligned_size),
),
sync_mapped_writes: Mutex::new(rank::BUFFER_SYNC_MAPPED_WRITES, None),
map_state: Mutex::new(rank::BUFFER_MAP_STATE, resource::BufferMapState::Idle),
label: desc.label.to_string(),
tracking_data: TrackingData::new(self.tracker_indices.buffers.clone()),
@ -697,7 +696,6 @@ impl<A: HalApi> Device<A> {
rank::BUFFER_INITIALIZATION_STATUS,
BufferInitTracker::new(0),
),
sync_mapped_writes: Mutex::new(rank::BUFFER_SYNC_MAPPED_WRITES, None),
map_state: Mutex::new(rank::BUFFER_MAP_STATE, resource::BufferMapState::Idle),
label: desc.label.to_string(),
tracking_data: TrackingData::new(self.tracker_indices.buffers.clone()),

View File

@ -120,7 +120,6 @@ define_lock_ranks! {
rank BUFFER_BIND_GROUPS "Buffer::bind_groups" followed by { }
rank BUFFER_INITIALIZATION_STATUS "Buffer::initialization_status" followed by { }
rank BUFFER_SYNC_MAPPED_WRITES "Buffer::sync_mapped_writes" followed by { }
rank DEVICE_DEFERRED_DESTROY "Device::deferred_destroy" followed by { }
rank DEVICE_FENCE "Device::fence" followed by { }
#[allow(dead_code)]

View File

@ -431,7 +431,6 @@ pub struct Buffer<A: HalApi> {
pub(crate) usage: wgt::BufferUsages,
pub(crate) size: wgt::BufferAddress,
pub(crate) initialization_status: RwLock<BufferInitTracker>,
pub(crate) sync_mapped_writes: Mutex<Option<hal::MemoryRange>>,
/// The `label` from the descriptor used to create the resource.
pub(crate) label: String,
pub(crate) tracking_data: TrackingData,