wgpu_core/command/
draw.rs

1use alloc::boxed::Box;
2
3use thiserror::Error;
4
5use crate::{
6    binding_model::{LateMinBufferBindingSizeMismatch, PushConstantUploadError},
7    resource::{
8        DestroyedResourceError, MissingBufferUsageError, MissingTextureUsageError,
9        ResourceErrorIdent,
10    },
11    track::ResourceUsageCompatibilityError,
12};
13
14use super::bind::BinderError;
15
16/// Error validating a draw call.
17#[derive(Clone, Debug, Error)]
18#[non_exhaustive]
19pub 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]
63pub 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 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:?}")]
85    InvalidViewportRect(Rect<f32>, wgt::Extent3d),
86    #[error("Viewport minDepth {0} and/or maxDepth {1} are not in [0, 1]")]
87    InvalidViewportDepth(f32, f32),
88    #[error("Scissor {0:?} is not contained in the render target {1:?}")]
89    InvalidScissorRect(Rect<u32>, wgt::Extent3d),
90    #[error("Support for {0} is not implemented yet")]
91    Unimplemented(&'static str),
92}
93
94#[derive(Clone, Copy, Debug, Default)]
95#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
96pub struct Rect<T> {
97    pub x: T,
98    pub y: T,
99    pub w: T,
100    pub h: T,
101}