diff --git a/wgpu-core/src/command/draw.rs b/wgpu-core/src/command/draw.rs index 39f2adf01bc..d5fa612fa63 100644 --- a/wgpu-core/src/command/draw.rs +++ b/wgpu-core/src/command/draw.rs @@ -87,8 +87,10 @@ pub enum RenderCommandError { MissingTextureUsage(#[from] MissingTextureUsageError), #[error(transparent)] PushConstants(#[from] PushConstantUploadError), - #[error("Invalid Viewport parameters")] - InvalidViewport, + #[error("Viewport width {0} and/or height {1} are less than or equal to 0")] + InvalidViewportDimension(f32, f32), + #[error("Viewport minDepth {0} and/or maxDepth {1} are not in [0, 1]")] + InvalidViewportDepth(f32, f32), #[error("Scissor {0:?} is not contained in the render target {1:?}")] InvalidScissorRect(Rect, wgt::Extent3d), #[error("Support for {0} is not implemented yet")] diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 61aa28484f0..e4f127af4b8 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -1451,14 +1451,18 @@ impl Global { depth_max, } => { let scope = PassErrorScope::SetViewport; - if rect.w <= 0.0 - || rect.h <= 0.0 - || depth_min < 0.0 - || depth_min > 1.0 - || depth_max < 0.0 - || depth_max > 1.0 + if rect.w <= 0.0 || rect.h <= 0.0 { + return Err(RenderCommandError::InvalidViewportDimension( + rect.w, rect.h, + )) + .map_pass_err(scope); + } + if depth_min < 0.0 || depth_min > 1.0 || depth_max < 0.0 || depth_max > 1.0 { - return Err(RenderCommandError::InvalidViewport).map_pass_err(scope); + return Err(RenderCommandError::InvalidViewportDepth( + depth_min, depth_max, + )) + .map_pass_err(scope); } let r = hal::Rect { x: rect.x,