| 1 |
use alloc::boxed::Box; |
| 2 |
|
| 3 |
use thiserror::Error; |
| 4 |
|
| 5 |
use crate::{ |
| 6 |
binding_model::{LateMinBufferBindingSizeMismatch, PushConstantUploadError}, |
| 7 |
resource::{ |
| 8 |
DestroyedResourceError, MissingBufferUsageError, MissingTextureUsageError, |
| 9 |
ResourceErrorIdent, |
| 10 |
}, |
| 11 |
track::ResourceUsageCompatibilityError, |
| 12 |
}; |
| 13 |
|
| 14 |
use super::bind::BinderError; |
| 15 |
|
| 16 |
/// Error validating a draw call. |
| 17 |
#[derive(Clone, Debug, Error)] |
| 18 |
#[non_exhaustive] |
| 19 |
pub enum DrawError { |
| 20 |
#[error("Blend constant needs to be set")] |
| 21 |
MissingBlendConstant, |
| 22 |
#[error("Render pipeline must be set")] |
| 23 |
MissingPipeline, |
| 24 |
#[error("Currently set {pipeline} requires vertex buffer {index} to be set")] |
| 25 |
MissingVertexBuffer { |
| 26 |
pipeline: ResourceErrorIdent, |
| 27 |
index: u32, |
| 28 |
}, |
| 29 |
#[error("Index buffer must be set")] |
| 30 |
MissingIndexBuffer, |
| 31 |
#[error(transparent)] |
| 32 |
IncompatibleBindGroup(#[from] Box<BinderError>), |
| 33 |
#[error("Vertex {last_vertex} extends beyond limit {vertex_limit} imposed by the buffer in slot {slot}. Did you bind the correct `Vertex` step-rate vertex buffer?")] |
| 34 |
VertexBeyondLimit { |
| 35 |
last_vertex: u64, |
| 36 |
vertex_limit: u64, |
| 37 |
slot: u32, |
| 38 |
}, |
| 39 |
#[error("Instance {last_instance} extends beyond limit {instance_limit} imposed by the buffer in slot {slot}. Did you bind the correct `Instance` step-rate vertex buffer?")] |
| 40 |
InstanceBeyondLimit { |
| 41 |
last_instance: u64, |
| 42 |
instance_limit: u64, |
| 43 |
slot: u32, |
| 44 |
}, |
| 45 |
#[error("Index {last_index} extends beyond limit {index_limit}. Did you bind the correct index buffer?")] |
| 46 |
IndexBeyondLimit { last_index: u64, index_limit: u64 }, |
| 47 |
#[error( |
| 48 |
"Index buffer format {buffer_format:?} doesn't match {pipeline}'s index format {pipeline_format:?}" |
| 49 |
)] |
| 50 |
UnmatchedIndexFormats { |
| 51 |
pipeline: ResourceErrorIdent, |
| 52 |
pipeline_format: wgt::IndexFormat, |
| 53 |
buffer_format: wgt::IndexFormat, |
| 54 |
}, |
| 55 |
#[error(transparent)] |
| 56 |
BindingSizeTooSmall(#[from] LateMinBufferBindingSizeMismatch), |
| 57 |
} |
| 58 |
|
| 59 |
/// Error encountered when encoding a render command. |
| 60 |
/// This is the shared error set between render bundles and passes. |
| 61 |
#[derive(Clone, Debug, Error)] |
| 62 |
#[non_exhaustive] |
| 63 |
pub enum RenderCommandError { |
| 64 |
#[error("Bind group index {index} is greater than the device's requested `max_bind_group` limit {max}")] |
| 65 |
BindGroupIndexOutOfRange { index: u32, max: u32 }, |
| 66 |
#[error("Vertex buffer index {index} is greater than the device's requested `max_vertex_buffers` limit {max}")] |
| 67 |
VertexBufferIndexOutOfRange { index: u32, max: u32 }, |
| 68 |
#[error("Render pipeline targets are incompatible with render pass")] |
| 69 |
IncompatiblePipelineTargets(#[from] crate::device::RenderPassCompatibilityError), |
| 70 |
#[error("{0} writes to depth, while the pass has read-only depth access")] |
| 71 |
IncompatibleDepthAccess(ResourceErrorIdent), |
| 72 |
#[error("{0} writes to stencil, while the pass has read-only stencil access")] |
| 73 |
IncompatibleStencilAccess(ResourceErrorIdent), |
| 74 |
#[error(transparent)] |
| 75 |
ResourceUsageCompatibility(#[from] ResourceUsageCompatibilityError), |
| 76 |
#[error(transparent)] |
| 77 |
DestroyedResource(#[from] DestroyedResourceError), |
| 78 |
#[error(transparent)] |
| 79 |
MissingBufferUsage(#[from] MissingBufferUsageError), |
| 80 |
#[error(transparent)] |
| 81 |
MissingTextureUsage(#[from] MissingTextureUsageError), |
| 82 |
#[error(transparent)] |
| 83 |
PushConstants(#[from] PushConstantUploadError), |
| 84 |
#[error("Viewport size {{ w: {w}, h: {h} }} greater than device's requested `max_texture_dimension_2d` limit {max}, or less than zero")] |
| 85 |
InvalidViewportRectSize { w: f32, h: f32, max: u32 }, |
| 86 |
#[error("Viewport has invalid rect {rect:?} for device's requested `max_texture_dimension_2d` limit; Origin less than -2 * `max_texture_dimension_2d` ({min}), or rect extends past 2 * `max_texture_dimension_2d` - 1 ({max})")] |
| 87 |
InvalidViewportRectPosition { rect: Rect<f32>, min: f32, max: f32 }, |
| 88 |
#[error("Viewport minDepth {0} and/or maxDepth {1} are not in [0, 1]")] |
| 89 |
InvalidViewportDepth(f32, f32), |
| 90 |
#[error("Scissor {0:?} is not contained in the render target {1:?}")] |
| 91 |
InvalidScissorRect(Rect<u32>, wgt::Extent3d), |
| 92 |
#[error("Support for {0} is not implemented yet")] |
| 93 |
Unimplemented(&'static str), |
| 94 |
} |
| 95 |
|
| 96 |
#[derive(Clone, Copy, Debug, Default)] |
| 97 |
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
| 98 |
pub struct Rect<T> { |
| 99 |
pub x: T, |
| 100 |
pub y: T, |
| 101 |
pub w: T, |
| 102 |
pub h: T, |
| 103 |
} |