mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-19 22:11:01 +01:00
Split EncoderStateError from CommandEncoderError (#7779)
This commit is contained in:
1 parent
e72c4d8326
commit
77d2b0017a
9 files changed
+54
-65
No files matched your search
@@ -308,23 +308,15 @@ fn encoder_operations_fail_while_pass_alive(ctx: TestingContext) {
|
||||
ctx.device.push_error_scope(wgpu::ErrorFilter::Validation);
|
||||
|
||||
log::info!("Testing operation {op_name:?} on a locked command encoder while a {pass_type:?} pass is active");
|
||||
fail(
|
||||
&ctx.device,
|
||||
|| op(&mut encoder),
|
||||
Some("Command encoder is locked"),
|
||||
);
|
||||
fail(&ctx.device, || op(&mut encoder), Some("encoder is locked"));
|
||||
|
||||
// Drop the pass - this also fails now since the encoder is invalid:
|
||||
fail(
|
||||
&ctx.device,
|
||||
|| drop(pass),
|
||||
Some("Command encoder is invalid"),
|
||||
);
|
||||
fail(&ctx.device, || drop(pass), Some("encoder is invalid"));
|
||||
// Also, it's not possible to create a new pass on the encoder:
|
||||
fail(
|
||||
&ctx.device,
|
||||
|| encoder.begin_compute_pass(&wgpu::ComputePassDescriptor::default()),
|
||||
Some("Command encoder is invalid"),
|
||||
Some("encoder is invalid"),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -334,16 +326,8 @@ fn encoder_operations_fail_while_pass_alive(ctx: TestingContext) {
|
||||
.device
|
||||
.create_command_encoder(&wgpu::CommandEncoderDescriptor::default());
|
||||
let pass = create_pass(&mut encoder, pass_type);
|
||||
fail(
|
||||
&ctx.device,
|
||||
|| encoder.finish(),
|
||||
Some("Command encoder is locked"),
|
||||
);
|
||||
fail(
|
||||
&ctx.device,
|
||||
|| drop(pass),
|
||||
Some("Command encoder is invalid"),
|
||||
);
|
||||
fail(&ctx.device, || encoder.finish(), Some("encoder is locked"));
|
||||
fail(&ctx.device, || drop(pass), Some("encoder is invalid"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ use core::ops::Range;
|
||||
use crate::device::trace::Command as TraceCommand;
|
||||
use crate::{
|
||||
api_log,
|
||||
command::CommandEncoderError,
|
||||
command::EncoderStateError,
|
||||
device::DeviceError,
|
||||
get_lowest_common_denom,
|
||||
global::Global,
|
||||
@@ -74,7 +74,7 @@ whereas subesource range specified start {subresource_base_array_layer} and coun
|
||||
#[error(transparent)]
|
||||
Device(#[from] DeviceError),
|
||||
#[error(transparent)]
|
||||
CommandEncoderError(#[from] CommandEncoderError),
|
||||
EncoderState(#[from] EncoderStateError),
|
||||
#[error(transparent)]
|
||||
InvalidResource(#[from] InvalidResourceError),
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ use wgt::{BufferAddress, DynamicOffset};
|
||||
use alloc::{borrow::Cow, boxed::Box, sync::Arc, vec::Vec};
|
||||
use core::{fmt, str};
|
||||
|
||||
use crate::command::EncoderStateError;
|
||||
use crate::ray_tracing::AsAction;
|
||||
use crate::{
|
||||
binding_model::{
|
||||
@@ -127,7 +128,7 @@ pub enum ComputePassErrorInner {
|
||||
#[error(transparent)]
|
||||
Device(#[from] DeviceError),
|
||||
#[error(transparent)]
|
||||
Encoder(#[from] CommandEncoderError),
|
||||
EncoderState(#[from] EncoderStateError),
|
||||
#[error("Parent encoder is invalid")]
|
||||
InvalidParentEncoder,
|
||||
#[error("Bind group index {index} is greater than the device's requested `max_bind_group` limit {max}")]
|
||||
@@ -301,7 +302,7 @@ impl Global {
|
||||
|
||||
match cmd_buf.data.lock().lock_encoder() {
|
||||
Ok(_) => {}
|
||||
Err(e) => return make_err(e, arc_desc),
|
||||
Err(e) => return make_err(e.into(), arc_desc),
|
||||
};
|
||||
|
||||
arc_desc.timestamp_writes = match desc
|
||||
|
||||
@@ -95,15 +95,15 @@ pub(crate) enum CommandEncoderStatus {
|
||||
|
||||
impl CommandEncoderStatus {
|
||||
/// Checks that the encoder is in the [`Self::Recording`] state.
|
||||
pub(crate) fn record(&mut self) -> Result<RecordingGuard<'_>, CommandEncoderError> {
|
||||
pub(crate) fn record(&mut self) -> Result<RecordingGuard<'_>, EncoderStateError> {
|
||||
match self {
|
||||
Self::Recording(_) => Ok(RecordingGuard { inner: self }),
|
||||
Self::Locked(_) => {
|
||||
*self = Self::Error;
|
||||
Err(CommandEncoderError::Locked)
|
||||
Err(EncoderStateError::Locked)
|
||||
}
|
||||
Self::Finished(_) => Err(CommandEncoderError::NotRecording),
|
||||
Self::Error => Err(CommandEncoderError::Invalid),
|
||||
Self::Finished(_) => Err(EncoderStateError::Ended),
|
||||
Self::Error => Err(EncoderStateError::Invalid),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ impl CommandEncoderStatus {
|
||||
/// Locks the encoder by putting it in the [`Self::Locked`] state.
|
||||
///
|
||||
/// Call [`Self::unlock_encoder`] to put the [`CommandBuffer`] back into the [`Self::Recording`] state.
|
||||
fn lock_encoder(&mut self) -> Result<(), CommandEncoderError> {
|
||||
fn lock_encoder(&mut self) -> Result<(), EncoderStateError> {
|
||||
match mem::replace(self, Self::Error) {
|
||||
Self::Recording(inner) => {
|
||||
*self = Self::Locked(inner);
|
||||
@@ -130,10 +130,10 @@ impl CommandEncoderStatus {
|
||||
}
|
||||
Self::Finished(inner) => {
|
||||
*self = Self::Finished(inner);
|
||||
Err(CommandEncoderError::NotRecording)
|
||||
Err(EncoderStateError::Ended)
|
||||
}
|
||||
Self::Locked(_) => Err(CommandEncoderError::Locked),
|
||||
Self::Error => Err(CommandEncoderError::Invalid),
|
||||
Self::Locked(_) => Err(EncoderStateError::Locked),
|
||||
Self::Error => Err(EncoderStateError::Invalid),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ impl CommandEncoderStatus {
|
||||
/// This function is the unlocking counterpart to [`Self::lock_encoder`].
|
||||
///
|
||||
/// It is only valid to call this function if the encoder is in the [`Self::Locked`] state.
|
||||
fn unlock_encoder(&mut self) -> Result<RecordingGuard<'_>, CommandEncoderError> {
|
||||
fn unlock_encoder(&mut self) -> Result<RecordingGuard<'_>, EncoderStateError> {
|
||||
match mem::replace(self, Self::Error) {
|
||||
Self::Locked(inner) => {
|
||||
*self = Self::Recording(inner);
|
||||
@@ -150,10 +150,10 @@ impl CommandEncoderStatus {
|
||||
}
|
||||
Self::Finished(inner) => {
|
||||
*self = Self::Finished(inner);
|
||||
Err(CommandEncoderError::NotRecording)
|
||||
Err(EncoderStateError::Ended)
|
||||
}
|
||||
Self::Recording(_) => Err(CommandEncoderError::Invalid),
|
||||
Self::Error => Err(CommandEncoderError::Invalid),
|
||||
Self::Recording(_) => Err(EncoderStateError::Invalid),
|
||||
Self::Error => Err(EncoderStateError::Invalid),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,10 +171,10 @@ impl CommandEncoderStatus {
|
||||
}
|
||||
Self::Finished(inner) => {
|
||||
*self = Self::Finished(inner);
|
||||
Err(CommandEncoderError::NotRecording)
|
||||
Err(EncoderStateError::Ended.into())
|
||||
}
|
||||
Self::Locked(_) => Err(CommandEncoderError::Locked),
|
||||
Self::Error => Err(CommandEncoderError::Invalid),
|
||||
Self::Locked(_) => Err(EncoderStateError::Locked.into()),
|
||||
Self::Error => Err(EncoderStateError::Invalid.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -725,18 +725,27 @@ impl<C: Clone> BasePass<C> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Errors related to the state of a command or pass encoder.
|
||||
#[derive(Clone, Debug, Error)]
|
||||
#[non_exhaustive]
|
||||
pub enum EncoderStateError {
|
||||
#[error("Encoder is invalid")]
|
||||
Invalid,
|
||||
#[error("Encoding must not have ended")]
|
||||
Ended,
|
||||
|
||||
/// Note: only command encoders can be locked (not pass encoders).
|
||||
#[error("Encoder is locked by a previously created render/compute pass. Before recording any new commands, the pass must be ended.")]
|
||||
Locked,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Error)]
|
||||
#[non_exhaustive]
|
||||
pub enum CommandEncoderError {
|
||||
#[error("Command encoder is invalid")]
|
||||
Invalid,
|
||||
#[error("Command encoder must be active")]
|
||||
NotRecording,
|
||||
#[error(transparent)]
|
||||
State(#[from] EncoderStateError),
|
||||
#[error(transparent)]
|
||||
Device(#[from] DeviceError),
|
||||
#[error("Command encoder is locked by a previously created render/compute pass. Before recording any new commands, the pass must be ended.")]
|
||||
Locked,
|
||||
|
||||
#[error(transparent)]
|
||||
InvalidColorAttachment(#[from] ColorAttachmentError),
|
||||
#[error(transparent)]
|
||||
|
||||
@@ -4,7 +4,7 @@ use core::{iter, mem};
|
||||
#[cfg(feature = "trace")]
|
||||
use crate::device::trace::Command as TraceCommand;
|
||||
use crate::{
|
||||
command::{CommandBuffer, CommandEncoderError},
|
||||
command::{CommandBuffer, EncoderStateError},
|
||||
device::{DeviceError, MissingFeatures},
|
||||
global::Global,
|
||||
id,
|
||||
@@ -96,7 +96,7 @@ pub enum QueryError {
|
||||
#[error(transparent)]
|
||||
Device(#[from] DeviceError),
|
||||
#[error(transparent)]
|
||||
Encoder(#[from] CommandEncoderError),
|
||||
EncoderState(#[from] EncoderStateError),
|
||||
#[error(transparent)]
|
||||
MissingFeature(#[from] MissingFeatures),
|
||||
#[error("Error encountered while trying to use queries")]
|
||||
|
||||
@@ -11,6 +11,7 @@ use wgt::{
|
||||
use crate::binding_model::BindGroup;
|
||||
use crate::command::{
|
||||
validate_and_begin_occlusion_query, validate_and_begin_pipeline_statistics_query,
|
||||
EncoderStateError,
|
||||
};
|
||||
use crate::init_tracker::BufferInitTrackerAction;
|
||||
use crate::pipeline::{RenderPipeline, VertexStep};
|
||||
@@ -662,7 +663,7 @@ pub enum RenderPassErrorInner {
|
||||
#[error(transparent)]
|
||||
ColorAttachment(#[from] ColorAttachmentError),
|
||||
#[error(transparent)]
|
||||
Encoder(#[from] CommandEncoderError),
|
||||
EncoderState(#[from] EncoderStateError),
|
||||
#[error("Parent encoder is invalid")]
|
||||
InvalidParentEncoder,
|
||||
#[error("The format of the {location} ({format:?}) is not resolvable")]
|
||||
@@ -1610,7 +1611,7 @@ impl Global {
|
||||
|
||||
match cmd_buf.data.lock().lock_encoder() {
|
||||
Ok(_) => {}
|
||||
Err(e) => return make_err(e, arc_desc),
|
||||
Err(e) => return make_err(e.into(), arc_desc),
|
||||
};
|
||||
|
||||
let err = fill_arc_desc(hub, desc, &mut arc_desc, &cmd_buf.device).err();
|
||||
|
||||
@@ -8,7 +8,7 @@ use wgt::{BufferAddress, BufferUsages, Extent3d, TextureSelector, TextureUsages}
|
||||
use crate::device::trace::Command as TraceCommand;
|
||||
use crate::{
|
||||
api_log,
|
||||
command::{clear_texture, CommandEncoderError},
|
||||
command::{clear_texture, EncoderStateError},
|
||||
conv,
|
||||
device::{Device, DeviceError, MissingDownlevelFlags},
|
||||
global::Global,
|
||||
@@ -161,7 +161,9 @@ pub enum TransferError {
|
||||
#[non_exhaustive]
|
||||
pub enum CopyError {
|
||||
#[error(transparent)]
|
||||
Encoder(#[from] CommandEncoderError),
|
||||
EncoderState(#[from] EncoderStateError),
|
||||
#[error(transparent)]
|
||||
Device(#[from] DeviceError),
|
||||
#[error("Copy error")]
|
||||
Transfer(#[from] TransferError),
|
||||
#[error(transparent)]
|
||||
@@ -170,12 +172,6 @@ pub enum CopyError {
|
||||
InvalidResource(#[from] InvalidResourceError),
|
||||
}
|
||||
|
||||
impl From<DeviceError> for CopyError {
|
||||
fn from(err: DeviceError) -> Self {
|
||||
CopyError::Encoder(CommandEncoderError::Device(err))
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn extract_texture_selector<T>(
|
||||
copy_texture: &wgt::TexelCopyTextureInfo<T>,
|
||||
copy_size: &Extent3d,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::{
|
||||
command::CommandBuffer,
|
||||
command::{CommandBuffer, EncoderStateError},
|
||||
device::DeviceError,
|
||||
global::Global,
|
||||
id::{BufferId, CommandEncoderId, TextureId},
|
||||
@@ -9,8 +9,6 @@ use crate::{
|
||||
track::ResourceUsageCompatibilityError,
|
||||
};
|
||||
|
||||
use super::CommandEncoderError;
|
||||
|
||||
impl Global {
|
||||
pub fn command_encoder_transition_resources(
|
||||
&self,
|
||||
@@ -85,7 +83,7 @@ pub enum TransitionResourcesError {
|
||||
#[error(transparent)]
|
||||
Device(#[from] DeviceError),
|
||||
#[error(transparent)]
|
||||
Encoder(#[from] CommandEncoderError),
|
||||
EncoderState(#[from] EncoderStateError),
|
||||
#[error(transparent)]
|
||||
InvalidResource(#[from] InvalidResourceError),
|
||||
#[error(transparent)]
|
||||
|
||||
@@ -13,7 +13,7 @@ use thiserror::Error;
|
||||
use wgt::{AccelerationStructureGeometryFlags, BufferAddress, IndexFormat, VertexFormat};
|
||||
|
||||
use crate::{
|
||||
command::CommandEncoderError,
|
||||
command::EncoderStateError,
|
||||
device::{DeviceError, MissingFeatures},
|
||||
id::{BlasId, BufferId, TlasId},
|
||||
resource::{
|
||||
@@ -50,7 +50,7 @@ pub enum CreateTlasError {
|
||||
#[derive(Clone, Debug, Error)]
|
||||
pub enum BuildAccelerationStructureError {
|
||||
#[error(transparent)]
|
||||
Encoder(#[from] CommandEncoderError),
|
||||
EncoderState(#[from] EncoderStateError),
|
||||
|
||||
#[error(transparent)]
|
||||
Device(#[from] DeviceError),
|
||||
|
||||
Reference in new issue
Block a user