From 0f096e70e7552cc30c23e21c8e34d63714d8d08f Mon Sep 17 00:00:00 2001 From: Jinlei Li Date: Fri, 3 Jun 2022 10:44:04 +0800 Subject: [PATCH] Improve InvalidViewport error message --- wgpu-core/src/command/draw.rs | 6 ++++-- wgpu-core/src/command/render.rs | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/wgpu-core/src/command/draw.rs b/wgpu-core/src/command/draw.rs index 39f2adf01b..d5fa612fa6 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 61aa28484f..9443bea895 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -1451,14 +1451,17 @@ 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 - { - return Err(RenderCommandError::InvalidViewport).map_pass_err(scope); + if rect.w <= 0.0 || rect.h <= 0.0 { + return Err(RenderCommandError::InvalidViewportDimension( + rect.w, rect.h, + )) + .map_pass_err(scope); + } + if !(0.0..=1.0).contains(&depth_min) || !(0.0..=1.0).contains(&depth_max) { + return Err(RenderCommandError::InvalidViewportDepth( + depth_min, depth_max, + )) + .map_pass_err(scope); } let r = hal::Rect { x: rect.x,