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("Render pipeline targets are incompatible with render pass")]
75 IncompatiblePipelineTargets(#[from] crate::device::RenderPassCompatibilityError),
76 #[error("{0} writes to depth, while the pass has read-only depth access")]
77 IncompatibleDepthAccess(ResourceErrorIdent),
78 #[error("{0} writes to stencil, while the pass has read-only stencil access")]
79 IncompatibleStencilAccess(ResourceErrorIdent),
80 #[error(transparent)]
81 ResourceUsageCompatibility(#[from] ResourceUsageCompatibilityError),
82 #[error(transparent)]
83 DestroyedResource(#[from] DestroyedResourceError),
84 #[error(transparent)]
85 MissingBufferUsage(#[from] MissingBufferUsageError),
86 #[error(transparent)]
87 MissingTextureUsage(#[from] MissingTextureUsageError),
88 #[error(transparent)]
89 PushConstants(#[from] PushConstantUploadError),
90 #[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:?}")]
91 InvalidViewportRect(Rect<f32>, wgt::Extent3d),
92 #[error("Viewport minDepth {0} and/or maxDepth {1} are not in [0, 1]")]
93 InvalidViewportDepth(f32, f32),
94 #[error("Scissor {0:?} is not contained in the render target {1:?}")]
95 InvalidScissorRect(Rect<u32>, wgt::Extent3d),
96 #[error("Support for {0} is not implemented yet")]
97 Unimplemented(&'static str),
98}
99
100#[derive(Clone, Copy, Debug, Default)]
101#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
102pub struct Rect<T> {
103 pub x: T,
104 pub y: T,
105 pub w: T,
106 pub h: T,
107}