simplify BufferTracker.set_single's return type

This commit is contained in:
teoxoy 2024-06-19 23:54:49 +02:00 committed by Teodor Tanasoaia
parent 862f19524f
commit a979d2ed46
6 changed files with 72 additions and 87 deletions

View File

@ -98,20 +98,18 @@ impl Global {
list.push(TraceCommand::ClearBuffer { dst, offset, size });
}
let (dst_buffer, dst_pending) = {
let buffer_guard = hub.buffers.read();
let dst_buffer = buffer_guard
.get(dst)
.map_err(|_| ClearError::InvalidBuffer(dst))?;
let dst_buffer = hub
.buffers
.get(dst)
.map_err(|_| ClearError::InvalidBuffer(dst))?;
dst_buffer.same_device_as(cmd_buf.as_ref())?;
dst_buffer.same_device_as(cmd_buf.as_ref())?;
let dst_pending = cmd_buf_data
.trackers
.buffers
.set_single(&dst_buffer, hal::BufferUses::COPY_DST);
cmd_buf_data
.trackers
.buffers
.set_single(dst_buffer, hal::BufferUses::COPY_DST)
.ok_or(ClearError::InvalidBuffer(dst))?
};
let snatch_guard = dst_buffer.device.snatchable_lock.read();
let dst_raw = dst_buffer
.raw

View File

@ -229,9 +229,7 @@ impl<A: HalApi> BakedCommands<A> {
// must already know about it.
let transition = device_tracker
.buffers
.set_single(&buffer, hal::BufferUses::COPY_DST)
.unwrap()
.1;
.set_single(&buffer, hal::BufferUses::COPY_DST);
let raw_buf = buffer
.raw

View File

@ -406,19 +406,16 @@ impl Global {
query_set.same_device_as(cmd_buf.as_ref())?;
let (dst_buffer, dst_pending) = {
let buffer_guard = hub.buffers.read();
let dst_buffer = buffer_guard
.get(destination)
.map_err(|_| QueryError::InvalidBuffer(destination))?;
let dst_buffer = hub
.buffers
.get(destination)
.map_err(|_| QueryError::InvalidBuffer(destination))?;
dst_buffer.same_device_as(cmd_buf.as_ref())?;
dst_buffer.same_device_as(cmd_buf.as_ref())?;
tracker
.buffers
.set_single(dst_buffer, hal::BufferUses::COPY_DST)
.ok_or(QueryError::InvalidBuffer(destination))?
};
let dst_pending = tracker
.buffers
.set_single(&dst_buffer, hal::BufferUses::COPY_DST);
let snatch_guard = dst_buffer.device.snatchable_lock.read();

View File

@ -592,20 +592,18 @@ impl Global {
let snatch_guard = device.snatchable_lock.read();
let (src_buffer, src_pending) = {
let buffer_guard = hub.buffers.read();
let src_buffer = buffer_guard
.get(source)
.map_err(|_| TransferError::InvalidBuffer(source))?;
let src_buffer = hub
.buffers
.get(source)
.map_err(|_| TransferError::InvalidBuffer(source))?;
src_buffer.same_device_as(cmd_buf.as_ref())?;
src_buffer.same_device_as(cmd_buf.as_ref())?;
let src_pending = cmd_buf_data
.trackers
.buffers
.set_single(&src_buffer, hal::BufferUses::COPY_SRC);
cmd_buf_data
.trackers
.buffers
.set_single(src_buffer, hal::BufferUses::COPY_SRC)
.ok_or(TransferError::InvalidBuffer(source))?
};
let src_raw = src_buffer
.raw
.get(&snatch_guard)
@ -616,20 +614,18 @@ impl Global {
// expecting only a single barrier
let src_barrier = src_pending.map(|pending| pending.into_hal(&src_buffer, &snatch_guard));
let (dst_buffer, dst_pending) = {
let buffer_guard = hub.buffers.read();
let dst_buffer = buffer_guard
.get(destination)
.map_err(|_| TransferError::InvalidBuffer(destination))?;
let dst_buffer = hub
.buffers
.get(destination)
.map_err(|_| TransferError::InvalidBuffer(destination))?;
dst_buffer.same_device_as(cmd_buf.as_ref())?;
dst_buffer.same_device_as(cmd_buf.as_ref())?;
let dst_pending = cmd_buf_data
.trackers
.buffers
.set_single(&dst_buffer, hal::BufferUses::COPY_DST);
cmd_buf_data
.trackers
.buffers
.set_single(dst_buffer, hal::BufferUses::COPY_DST)
.ok_or(TransferError::InvalidBuffer(destination))?
};
let dst_raw = dst_buffer
.raw
.get(&snatch_guard)
@ -798,19 +794,17 @@ impl Global {
&snatch_guard,
)?;
let (src_buffer, src_pending) = {
let buffer_guard = hub.buffers.read();
let src_buffer = buffer_guard
.get(source.buffer)
.map_err(|_| TransferError::InvalidBuffer(source.buffer))?;
let src_buffer = hub
.buffers
.get(source.buffer)
.map_err(|_| TransferError::InvalidBuffer(source.buffer))?;
src_buffer.same_device_as(cmd_buf.as_ref())?;
src_buffer.same_device_as(cmd_buf.as_ref())?;
let src_pending = tracker
.buffers
.set_single(&src_buffer, hal::BufferUses::COPY_SRC);
tracker
.buffers
.set_single(src_buffer, hal::BufferUses::COPY_SRC)
.ok_or(TransferError::InvalidBuffer(source.buffer))?
};
let src_raw = src_buffer
.raw
.get(&snatch_guard)
@ -983,19 +977,17 @@ impl Global {
}
let src_barrier = src_pending.map(|pending| pending.into_hal(src_raw));
let (dst_buffer, dst_pending) = {
let buffer_guard = hub.buffers.read();
let dst_buffer = buffer_guard
.get(destination.buffer)
.map_err(|_| TransferError::InvalidBuffer(destination.buffer))?;
let dst_buffer = hub
.buffers
.get(destination.buffer)
.map_err(|_| TransferError::InvalidBuffer(destination.buffer))?;
dst_buffer.same_device_as(cmd_buf.as_ref())?;
dst_buffer.same_device_as(cmd_buf.as_ref())?;
let dst_pending = tracker
.buffers
.set_single(&dst_buffer, hal::BufferUses::COPY_DST);
tracker
.buffers
.set_single(dst_buffer, hal::BufferUses::COPY_DST)
.ok_or(TransferError::InvalidBuffer(destination.buffer))?
};
let dst_raw = dst_buffer
.raw
.get(&snatch_guard)

View File

@ -605,17 +605,16 @@ impl Global {
) -> Result<(), QueueWriteError> {
let hub = A::hub(self);
let (dst, transition) = {
let buffer_guard = hub.buffers.read();
let dst = buffer_guard
.get(buffer_id)
.map_err(|_| TransferError::InvalidBuffer(buffer_id))?;
let dst = hub
.buffers
.get(buffer_id)
.map_err(|_| TransferError::InvalidBuffer(buffer_id))?;
let transition = {
let mut trackers = device.trackers.lock();
trackers
.buffers
.set_single(dst, hal::BufferUses::COPY_DST)
.ok_or(TransferError::InvalidBuffer(buffer_id))?
trackers.buffers.set_single(&dst, hal::BufferUses::COPY_DST)
};
let snatch_guard = device.snatchable_lock.read();
let dst_raw = dst
.raw
@ -650,7 +649,7 @@ impl Global {
region.into_iter(),
);
}
let dst = hub.buffers.get(buffer_id).unwrap();
pending_writes.dst_buffers.insert(buffer_id, dst.clone());
// Ensure the overwritten bytes are marked as initialized so

View File

@ -286,9 +286,6 @@ impl<A: HalApi> BufferUsageScope<A> {
}
}
pub(crate) type SetSingleResult<A> =
Option<(Arc<Buffer<A>>, Option<PendingTransition<BufferUses>>)>;
/// Stores all buffer state within a command buffer or device.
pub(crate) struct BufferTracker<A: HalApi> {
start: Vec<BufferUses>,
@ -454,7 +451,11 @@ impl<A: HalApi> BufferTracker<A> {
///
/// If the ID is higher than the length of internal vectors,
/// the vectors will be extended. A call to set_size is not needed.
pub fn set_single(&mut self, buffer: &Arc<Buffer<A>>, state: BufferUses) -> SetSingleResult<A> {
pub fn set_single(
&mut self,
buffer: &Arc<Buffer<A>>,
state: BufferUses,
) -> Option<PendingTransition<BufferUses>> {
let index: usize = buffer.as_info().tracker_index().as_usize();
self.allow_index(index);
@ -478,7 +479,7 @@ impl<A: HalApi> BufferTracker<A> {
strict_assert!(self.temp.len() <= 1);
Some((buffer.clone(), self.temp.pop()))
self.temp.pop()
}
/// Sets the given state for all buffers in the given tracker.