mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-25 16:24:24 +00:00
reorder map_async
validation steps
This commit is contained in:
parent
cc7b2db235
commit
284c807abc
@ -485,19 +485,6 @@ impl<A: HalApi> Buffer<A> {
|
||||
size: Option<wgt::BufferAddress>,
|
||||
op: BufferMapOperation,
|
||||
) -> Result<(), (BufferMapOperation, BufferAccessError)> {
|
||||
let (pub_usage, internal_use) = match op.host {
|
||||
HostMap::Read => (wgt::BufferUsages::MAP_READ, hal::BufferUses::MAP_READ),
|
||||
HostMap::Write => (wgt::BufferUsages::MAP_WRITE, hal::BufferUses::MAP_WRITE),
|
||||
};
|
||||
|
||||
{
|
||||
{
|
||||
let snatch_guard = self.device.snatchable_lock.read();
|
||||
if self.is_destroyed(&snatch_guard) {
|
||||
return Err((op, BufferAccessError::Destroyed));
|
||||
}
|
||||
}
|
||||
|
||||
let range_size = if let Some(size) = size {
|
||||
size
|
||||
} else if offset > self.size {
|
||||
@ -515,18 +502,16 @@ impl<A: HalApi> Buffer<A> {
|
||||
|
||||
let range = offset..(offset + range_size);
|
||||
|
||||
if range.start % wgt::MAP_ALIGNMENT != 0 || range.end % wgt::COPY_BUFFER_ALIGNMENT != 0
|
||||
{
|
||||
if range.start % wgt::MAP_ALIGNMENT != 0 || range.end % wgt::COPY_BUFFER_ALIGNMENT != 0 {
|
||||
return Err((op, BufferAccessError::UnalignedRange));
|
||||
}
|
||||
|
||||
let device = &self.device;
|
||||
if !device.is_valid() {
|
||||
return Err((op, DeviceError::Lost.into()));
|
||||
}
|
||||
let (pub_usage, internal_use) = match op.host {
|
||||
HostMap::Read => (wgt::BufferUsages::MAP_READ, hal::BufferUses::MAP_READ),
|
||||
HostMap::Write => (wgt::BufferUsages::MAP_WRITE, hal::BufferUses::MAP_WRITE),
|
||||
};
|
||||
|
||||
if let Err(e) =
|
||||
crate::validation::check_buffer_usage(self.info.id(), self.usage, pub_usage)
|
||||
if let Err(e) = crate::validation::check_buffer_usage(self.info.id(), self.usage, pub_usage)
|
||||
{
|
||||
return Err((op, e.into()));
|
||||
}
|
||||
@ -550,6 +535,18 @@ impl<A: HalApi> Buffer<A> {
|
||||
));
|
||||
}
|
||||
|
||||
let device = &self.device;
|
||||
if let Err(e) = device.check_is_valid() {
|
||||
return Err((op, e.into()));
|
||||
}
|
||||
|
||||
{
|
||||
let snatch_guard = device.snatchable_lock.read();
|
||||
if self.is_destroyed(&snatch_guard) {
|
||||
return Err((op, BufferAccessError::Destroyed));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let map_state = &mut *self.map_state.lock();
|
||||
*map_state = match *map_state {
|
||||
@ -567,19 +564,16 @@ impl<A: HalApi> Buffer<A> {
|
||||
};
|
||||
}
|
||||
|
||||
let snatch_guard = self.device.snatchable_lock.read();
|
||||
|
||||
let snatch_guard = device.snatchable_lock.read();
|
||||
{
|
||||
let mut trackers = self.device.as_ref().trackers.lock();
|
||||
let mut trackers = device.as_ref().trackers.lock();
|
||||
trackers.buffers.set_single(self, internal_use);
|
||||
//TODO: Check if draining ALL buffers is correct!
|
||||
let _ = trackers.buffers.drain_transitions(&snatch_guard);
|
||||
}
|
||||
|
||||
drop(snatch_guard);
|
||||
}
|
||||
|
||||
self.device.lock_life().map(self);
|
||||
device.lock_life().map(self);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user