Skip to content

Commit 7cab174

Browse files
authored
Loosen Viewport validation requirements to match the new specs (gfx-rs#7564)
1 parent bbff2c4 commit 7cab174

4 files changed

Lines changed: 33 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ Naga now infers the correct binding layout when a resource appears only in an as
5959

6060
### Changes
6161

62+
- Loosen Viewport validation requirements to match the [new specs](https://github.com/gpuweb/gpuweb/pull/5025). By @ebbdrop in [#7564](https://github.com/gfx-rs/wgpu/pull/7564)
63+
6264
#### General
6365

6466
- Removed `MaintainBase` in favor of using `PollType`. By @waywardmonkeys in [#7508](https://github.com/gfx-rs/wgpu/pull/7508).

tests/tests/wgpu-gpu/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static DROP_ENCODER_AFTER_ERROR: GpuTestConfiguration = GpuTestConfiguration::ne
6868
renderpass.set_viewport(0.0, 0.0, -1.0, -1.0, 0.0, 1.0);
6969
drop(renderpass);
7070
},
71-
Some("viewport has invalid rect"),
71+
Some("less than zero"),
7272
);
7373

7474
// This is the actual interesting error condition. We've created

wgpu-core/src/command/draw.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ pub enum RenderCommandError {
8181
MissingTextureUsage(#[from] MissingTextureUsageError),
8282
#[error(transparent)]
8383
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),
84+
#[error("Viewport size {{ w: {w}, h: {h} }} greater than device's requested `max_texture_dimension_2d` limit {max}, or less than zero")]
85+
InvalidViewportRectSize { w: f32, h: f32, max: u32 },
86+
#[error("Viewport has invalid rect {rect:?} for device's requested `max_texture_dimension_2d` limit; Origin less than -2 * `max_texture_dimension_2d` ({min}), or rect extends past 2 * `max_texture_dimension_2d` - 1 ({max})")]
87+
InvalidViewportRectPosition { rect: Rect<f32>, min: f32, max: f32 },
8688
#[error("Viewport minDepth {0} and/or maxDepth {1} are not in [0, 1]")]
8789
InvalidViewportDepth(f32, f32),
8890
#[error("Scissor {0:?} is not contained in the render target {1:?}")]

wgpu-core/src/command/render.rs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,14 +2347,33 @@ fn set_viewport(
23472347
depth_max: f32,
23482348
) -> Result<(), RenderPassErrorInner> {
23492349
api_log!("RenderPass::set_viewport {rect:?}");
2350-
if rect.x < 0.0
2351-
|| rect.y < 0.0
2352-
|| rect.w <= 0.0
2353-
|| rect.h <= 0.0
2354-
|| rect.x + rect.w > state.info.extent.width as f32
2355-
|| rect.y + rect.h > state.info.extent.height as f32
2350+
2351+
if rect.w < 0.0
2352+
|| rect.h < 0.0
2353+
|| rect.w > state.device.limits.max_texture_dimension_2d as f32
2354+
|| rect.h > state.device.limits.max_texture_dimension_2d as f32
23562355
{
2357-
return Err(RenderCommandError::InvalidViewportRect(rect, state.info.extent).into());
2356+
return Err(RenderCommandError::InvalidViewportRectSize {
2357+
w: rect.w,
2358+
h: rect.h,
2359+
max: state.device.limits.max_texture_dimension_2d,
2360+
}
2361+
.into());
2362+
}
2363+
2364+
let max_viewport_range = state.device.limits.max_texture_dimension_2d as f32 * 2.0;
2365+
2366+
if rect.x < -max_viewport_range
2367+
|| rect.y < -max_viewport_range
2368+
|| rect.x + rect.w > max_viewport_range - 1.0
2369+
|| rect.y + rect.h > max_viewport_range - 1.0
2370+
{
2371+
return Err(RenderCommandError::InvalidViewportRectPosition {
2372+
rect,
2373+
min: -max_viewport_range,
2374+
max: max_viewport_range - 1.0,
2375+
}
2376+
.into());
23582377
}
23592378
if !(0.0..=1.0).contains(&depth_min) || !(0.0..=1.0).contains(&depth_max) {
23602379
return Err(RenderCommandError::InvalidViewportDepth(depth_min, depth_max).into());

0 commit comments

Comments
 (0)