Skip to content

Commit

Permalink
Improve InvalidViewport error message
Browse files Browse the repository at this point in the history
  • Loading branch information
jinleili committed Jun 3, 2022
1 parent 75db572 commit 7b42c74
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
6 changes: 4 additions & 2 deletions wgpu-core/src/command/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32>, wgt::Extent3d),
#[error("Support for {0} is not implemented yet")]
Expand Down
18 changes: 11 additions & 7 deletions wgpu-core/src/command/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1451,14 +1451,18 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
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,
Expand Down

0 comments on commit 7b42c74

Please sign in to comment.