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