mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-21 22:33:49 +00:00
use EncoderGuard
for the other command encoder operations
The spec requires us to invalidate the encoder if there was any error during the body of these operations.
This commit is contained in:
parent
349ff853d1
commit
459ee2c149
@ -92,7 +92,8 @@ impl Global {
|
||||
.command_buffers
|
||||
.get(command_encoder_id.into_command_buffer_id());
|
||||
let mut cmd_buf_data = cmd_buf.data.lock();
|
||||
let cmd_buf_data = cmd_buf_data.record()?;
|
||||
let mut cmd_buf_data_guard = cmd_buf_data.record()?;
|
||||
let cmd_buf_data = &mut *cmd_buf_data_guard;
|
||||
|
||||
#[cfg(feature = "trace")]
|
||||
if let Some(ref mut list) = cmd_buf_data.commands {
|
||||
@ -138,6 +139,8 @@ impl Global {
|
||||
|
||||
if offset == end_offset {
|
||||
log::trace!("Ignoring fill_buffer of size 0");
|
||||
|
||||
cmd_buf_data_guard.mark_successful();
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@ -157,6 +160,8 @@ impl Global {
|
||||
cmd_buf_raw.transition_buffers(dst_barrier.as_slice());
|
||||
cmd_buf_raw.clear_buffer(dst_raw, offset..end_offset);
|
||||
}
|
||||
|
||||
cmd_buf_data_guard.mark_successful();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -175,7 +180,8 @@ impl Global {
|
||||
.command_buffers
|
||||
.get(command_encoder_id.into_command_buffer_id());
|
||||
let mut cmd_buf_data = cmd_buf.data.lock();
|
||||
let cmd_buf_data = cmd_buf_data.record()?;
|
||||
let mut cmd_buf_data_guard = cmd_buf_data.record()?;
|
||||
let cmd_buf_data = &mut *cmd_buf_data_guard;
|
||||
|
||||
#[cfg(feature = "trace")]
|
||||
if let Some(ref mut list) = cmd_buf_data.commands {
|
||||
@ -243,7 +249,10 @@ impl Global {
|
||||
&device.alignments,
|
||||
device.zero_buffer.as_ref(),
|
||||
&snatch_guard,
|
||||
)
|
||||
)?;
|
||||
|
||||
cmd_buf_data_guard.mark_successful();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,9 +91,9 @@ pub(crate) enum CommandEncoderStatus {
|
||||
|
||||
impl CommandEncoderStatus {
|
||||
/// Checks that the encoder is in the [`Self::Recording`] state.
|
||||
pub(crate) fn record(&mut self) -> Result<&mut CommandBufferMutable, CommandEncoderError> {
|
||||
pub(crate) fn record(&mut self) -> Result<RecordingGuard<'_>, CommandEncoderError> {
|
||||
match self {
|
||||
Self::Recording(inner) => Ok(inner),
|
||||
Self::Recording(_) => Ok(RecordingGuard { inner: self }),
|
||||
Self::Locked(_) => {
|
||||
*self = Self::Error;
|
||||
Err(CommandEncoderError::Locked)
|
||||
@ -717,7 +717,8 @@ impl Global {
|
||||
|
||||
let cmd_buf = hub.command_buffers.get(encoder_id.into_command_buffer_id());
|
||||
let mut cmd_buf_data = cmd_buf.data.lock();
|
||||
let cmd_buf_data = cmd_buf_data.record()?;
|
||||
let mut cmd_buf_data_guard = cmd_buf_data.record()?;
|
||||
let cmd_buf_data = &mut *cmd_buf_data_guard;
|
||||
|
||||
#[cfg(feature = "trace")]
|
||||
if let Some(ref mut list) = cmd_buf_data.commands {
|
||||
@ -734,6 +735,8 @@ impl Global {
|
||||
cmd_buf_raw.begin_debug_marker(label);
|
||||
}
|
||||
}
|
||||
|
||||
cmd_buf_data_guard.mark_successful();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -749,7 +752,8 @@ impl Global {
|
||||
|
||||
let cmd_buf = hub.command_buffers.get(encoder_id.into_command_buffer_id());
|
||||
let mut cmd_buf_data = cmd_buf.data.lock();
|
||||
let cmd_buf_data = cmd_buf_data.record()?;
|
||||
let mut cmd_buf_data_guard = cmd_buf_data.record()?;
|
||||
let cmd_buf_data = &mut *cmd_buf_data_guard;
|
||||
|
||||
#[cfg(feature = "trace")]
|
||||
if let Some(ref mut list) = cmd_buf_data.commands {
|
||||
@ -766,6 +770,8 @@ impl Global {
|
||||
cmd_buf_raw.insert_debug_marker(label);
|
||||
}
|
||||
}
|
||||
|
||||
cmd_buf_data_guard.mark_successful();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -780,7 +786,8 @@ impl Global {
|
||||
|
||||
let cmd_buf = hub.command_buffers.get(encoder_id.into_command_buffer_id());
|
||||
let mut cmd_buf_data = cmd_buf.data.lock();
|
||||
let cmd_buf_data = cmd_buf_data.record()?;
|
||||
let mut cmd_buf_data_guard = cmd_buf_data.record()?;
|
||||
let cmd_buf_data = &mut *cmd_buf_data_guard;
|
||||
|
||||
#[cfg(feature = "trace")]
|
||||
if let Some(ref mut list) = cmd_buf_data.commands {
|
||||
@ -797,6 +804,8 @@ impl Global {
|
||||
cmd_buf_raw.end_debug_marker();
|
||||
}
|
||||
}
|
||||
|
||||
cmd_buf_data_guard.mark_successful();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -322,7 +322,8 @@ impl Global {
|
||||
.command_buffers
|
||||
.get(command_encoder_id.into_command_buffer_id());
|
||||
let mut cmd_buf_data = cmd_buf.data.lock();
|
||||
let cmd_buf_data = cmd_buf_data.record()?;
|
||||
let mut cmd_buf_data_guard = cmd_buf_data.record()?;
|
||||
let cmd_buf_data = &mut *cmd_buf_data_guard;
|
||||
|
||||
cmd_buf
|
||||
.device
|
||||
@ -344,6 +345,7 @@ impl Global {
|
||||
|
||||
cmd_buf_data.trackers.query_sets.insert_single(query_set);
|
||||
|
||||
cmd_buf_data_guard.mark_successful();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -362,7 +364,8 @@ impl Global {
|
||||
.command_buffers
|
||||
.get(command_encoder_id.into_command_buffer_id());
|
||||
let mut cmd_buf_data = cmd_buf.data.lock();
|
||||
let cmd_buf_data = cmd_buf_data.record()?;
|
||||
let mut cmd_buf_data_guard = cmd_buf_data.record()?;
|
||||
let cmd_buf_data = &mut *cmd_buf_data_guard;
|
||||
|
||||
#[cfg(feature = "trace")]
|
||||
if let Some(ref mut list) = cmd_buf_data.commands {
|
||||
@ -457,6 +460,7 @@ impl Global {
|
||||
|
||||
cmd_buf_data.trackers.query_sets.insert_single(query_set);
|
||||
|
||||
cmd_buf_data_guard.mark_successful();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -173,7 +173,8 @@ impl Global {
|
||||
let mut scratch_buffer_blas_size = 0;
|
||||
let mut blas_storage = Vec::new();
|
||||
let mut cmd_buf_data = cmd_buf.data.lock();
|
||||
let cmd_buf_data = cmd_buf_data.record()?;
|
||||
let mut cmd_buf_data_guard = cmd_buf_data.record()?;
|
||||
let cmd_buf_data = &mut *cmd_buf_data_guard;
|
||||
|
||||
iter_blas(
|
||||
blas_iter,
|
||||
@ -355,6 +356,7 @@ impl Global {
|
||||
.consume_temp(TempResource::ScratchBuffer(scratch_buffer));
|
||||
}
|
||||
|
||||
cmd_buf_data_guard.mark_successful();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -488,7 +490,8 @@ impl Global {
|
||||
let mut scratch_buffer_blas_size = 0;
|
||||
let mut blas_storage = Vec::new();
|
||||
let mut cmd_buf_data = cmd_buf.data.lock();
|
||||
let cmd_buf_data = cmd_buf_data.record()?;
|
||||
let mut cmd_buf_data_guard = cmd_buf_data.record()?;
|
||||
let cmd_buf_data = &mut *cmd_buf_data_guard;
|
||||
|
||||
iter_blas(
|
||||
blas_iter,
|
||||
@ -761,6 +764,7 @@ impl Global {
|
||||
.consume_temp(TempResource::ScratchBuffer(scratch_buffer));
|
||||
}
|
||||
|
||||
cmd_buf_data_guard.mark_successful();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -532,7 +532,8 @@ impl Global {
|
||||
.command_buffers
|
||||
.get(command_encoder_id.into_command_buffer_id());
|
||||
let mut cmd_buf_data = cmd_buf.data.lock();
|
||||
let cmd_buf_data = cmd_buf_data.record()?;
|
||||
let mut cmd_buf_data_guard = cmd_buf_data.record()?;
|
||||
let cmd_buf_data = &mut *cmd_buf_data_guard;
|
||||
|
||||
let device = &cmd_buf.device;
|
||||
device.check_is_valid()?;
|
||||
@ -634,6 +635,7 @@ impl Global {
|
||||
|
||||
if size == 0 {
|
||||
log::trace!("Ignoring copy_buffer_to_buffer of size 0");
|
||||
cmd_buf_data_guard.mark_successful();
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@ -667,6 +669,8 @@ impl Global {
|
||||
cmd_buf_raw.transition_buffers(&barriers);
|
||||
cmd_buf_raw.copy_buffer_to_buffer(src_raw, dst_raw, &[region]);
|
||||
}
|
||||
|
||||
cmd_buf_data_guard.mark_successful();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -690,7 +694,8 @@ impl Global {
|
||||
.command_buffers
|
||||
.get(command_encoder_id.into_command_buffer_id());
|
||||
let mut cmd_buf_data = cmd_buf.data.lock();
|
||||
let cmd_buf_data = cmd_buf_data.record()?;
|
||||
let mut cmd_buf_data_guard = cmd_buf_data.record()?;
|
||||
let cmd_buf_data = &mut *cmd_buf_data_guard;
|
||||
|
||||
let device = &cmd_buf.device;
|
||||
device.check_is_valid()?;
|
||||
@ -706,6 +711,7 @@ impl Global {
|
||||
|
||||
if copy_size.width == 0 || copy_size.height == 0 || copy_size.depth_or_array_layers == 0 {
|
||||
log::trace!("Ignoring copy_buffer_to_texture of size 0");
|
||||
cmd_buf_data_guard.mark_successful();
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@ -820,6 +826,8 @@ impl Global {
|
||||
cmd_buf_raw.transition_buffers(src_barrier.as_slice());
|
||||
cmd_buf_raw.copy_buffer_to_texture(src_raw, dst_raw, ®ions);
|
||||
}
|
||||
|
||||
cmd_buf_data_guard.mark_successful();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -843,7 +851,8 @@ impl Global {
|
||||
.command_buffers
|
||||
.get(command_encoder_id.into_command_buffer_id());
|
||||
let mut cmd_buf_data = cmd_buf.data.lock();
|
||||
let cmd_buf_data = cmd_buf_data.record()?;
|
||||
let mut cmd_buf_data_guard = cmd_buf_data.record()?;
|
||||
let cmd_buf_data = &mut *cmd_buf_data_guard;
|
||||
|
||||
let device = &cmd_buf.device;
|
||||
device.check_is_valid()?;
|
||||
@ -859,6 +868,7 @@ impl Global {
|
||||
|
||||
if copy_size.width == 0 || copy_size.height == 0 || copy_size.depth_or_array_layers == 0 {
|
||||
log::trace!("Ignoring copy_texture_to_buffer of size 0");
|
||||
cmd_buf_data_guard.mark_successful();
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@ -987,6 +997,8 @@ impl Global {
|
||||
®ions,
|
||||
);
|
||||
}
|
||||
|
||||
cmd_buf_data_guard.mark_successful();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -1010,7 +1022,8 @@ impl Global {
|
||||
.command_buffers
|
||||
.get(command_encoder_id.into_command_buffer_id());
|
||||
let mut cmd_buf_data = cmd_buf.data.lock();
|
||||
let cmd_buf_data = cmd_buf_data.record()?;
|
||||
let mut cmd_buf_data_guard = cmd_buf_data.record()?;
|
||||
let cmd_buf_data = &mut *cmd_buf_data_guard;
|
||||
|
||||
let device = &cmd_buf.device;
|
||||
device.check_is_valid()?;
|
||||
@ -1028,6 +1041,7 @@ impl Global {
|
||||
|
||||
if copy_size.width == 0 || copy_size.height == 0 || copy_size.depth_or_array_layers == 0 {
|
||||
log::trace!("Ignoring copy_texture_to_texture of size 0");
|
||||
cmd_buf_data_guard.mark_successful();
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@ -1147,6 +1161,7 @@ impl Global {
|
||||
);
|
||||
}
|
||||
|
||||
cmd_buf_data_guard.mark_successful();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -1481,15 +1481,17 @@ impl Global {
|
||||
|
||||
let cmd_buf = hub.command_buffers.get(id.into_command_buffer_id());
|
||||
let mut cmd_buf_data = cmd_buf.data.lock();
|
||||
let cmd_buf_data = cmd_buf_data.record();
|
||||
let cmd_buf_data_guard = cmd_buf_data.record();
|
||||
|
||||
if let Ok(cmd_buf_data) = cmd_buf_data {
|
||||
let cmd_buf_raw = cmd_buf_data
|
||||
if let Ok(mut cmd_buf_data_guard) = cmd_buf_data_guard {
|
||||
let cmd_buf_raw = cmd_buf_data_guard
|
||||
.encoder
|
||||
.open(&cmd_buf.device)
|
||||
.ok()
|
||||
.and_then(|encoder| encoder.as_any_mut().downcast_mut());
|
||||
hal_command_encoder_callback(cmd_buf_raw)
|
||||
let ret = hal_command_encoder_callback(cmd_buf_raw);
|
||||
cmd_buf_data_guard.mark_successful();
|
||||
ret
|
||||
} else {
|
||||
hal_command_encoder_callback(None)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user