Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation in accordance with WebGPU setViewport valid usage fo… #4058

Merged
merged 2 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ By @Valaphee in [#3402](https://github.com/gfx-rs/wgpu/pull/3402)

- Omit texture store bound checks since they are no-ops if out of bounds on all APIs. By @teoxoy in [#3975](https://github.com/gfx-rs/wgpu/pull/3975)
- Validate `DownlevelFlags::READ_ONLY_DEPTH_STENCIL`. By @teoxoy in [#4031](https://github.com/gfx-rs/wgpu/pull/4031)
- Add validation in accordance with WebGPU `setViewport` valid usage for `x`, `y` and `this.[[attachment_size]]`. By @James2022-rgb in [#4058](https://github.com/gfx-rs/wgpu/pull/4058)

### Bug Fixes

Expand Down
4 changes: 2 additions & 2 deletions wgpu-core/src/command/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ pub enum RenderCommandError {
MissingTextureUsage(#[from] MissingTextureUsageError),
#[error(transparent)]
PushConstants(#[from] PushConstantUploadError),
#[error("Viewport width {0} and/or height {1} are less than or equal to 0")]
InvalidViewportDimension(f32, f32),
#[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:?}")]
InvalidViewportRect(Rect<f32>, wgt::Extent3d),
#[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:?}")]
Expand Down
13 changes: 10 additions & 3 deletions wgpu-core/src/command/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1727,9 +1727,16 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
depth_max,
} => {
let scope = PassErrorScope::SetViewport;
if rect.w <= 0.0 || rect.h <= 0.0 {
return Err(RenderCommandError::InvalidViewportDimension(
rect.w, rect.h,
if rect.x < 0.0
|| rect.y < 0.0
|| rect.w <= 0.0
|| rect.h <= 0.0
|| rect.x + rect.w > info.extent.width as f32
|| rect.y + rect.h > info.extent.height as f32
{
return Err(RenderCommandError::InvalidViewportRect(
*rect,
info.extent,
))
.map_pass_err(scope);
}
Expand Down
Loading