895: Improve validation in B2B copies and RenderCommands r=kvark a=kunalmohan

**Connections**
_Link to the issues addressed by this PR, or dependent PRs in other repositories_

**Description**
_Describe what problem this is solving, and how it's solved._
Validation for the following have been added-
- Validate all parameters in B2B copy even if `copy_size == 0`.
- Check for copy operations issued within same buffer.
- `RenderPass.setViewport()`
- `RenderPass.setScissorRect()`

**Testing**
_Explain how this change is tested._
Tested with CTS in Servo. More tests pass now. Will test on wgpu-rs now.
<!--
Non-trivial functional changes would need to be tested through:
  - [wgpu-rs](https://github.com/gfx-rs/wgpu-rs) - test the examples.
  - [wgpu-native](https://github.com/gfx-rs/wgpu-native/) - check the generated C header for sanity.

Ideally, a PR needs to link to the draft PRs in these projects with relevant modifications.
See https://github.com/gfx-rs/wgpu/pull/666 for an example.
If you can add a unit/integration test here in `wgpu`, that would be best.
-->


Co-authored-by: Kunal Mohan <kunalmohan99@gmail.com>
This commit is contained in:
bors[bot]andKunal Mohan authored and GitHub committed 2020-08-24 18:00:47 +00:00
commit 59f0996eab
3 files changed
+45 -5

No files matched your search

+4
View File
@@ -71,6 +71,10 @@ pub enum RenderCommandError {
MissingTextureUsage(#[from] MissingTextureUsageError),
#[error(transparent)]
PushConstants(#[from] PushConstantUploadError),
#[error("Invalid Viewport parameters")]
InvalidViewport,
#[error("Invalid ScissorRect parameters")]
InvalidScissorRect,
}
#[derive(Clone, Copy, Debug, Default)]
+31
View File
@@ -316,6 +316,8 @@ pub enum RenderPassError {
Encoder(#[from] CommandEncoderError),
#[error("attachment texture view {0:?} is invalid")]
InvalidAttachment(id::TextureViewId),
#[error("attachments have different sizes")]
MismatchAttachments,
#[error("attachment's sample count {0} is invalid")]
InvalidSampleCount(u8),
#[error("attachment with resolve target must be multi-sampled")]
@@ -466,6 +468,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
let mut output_attachments = AttachmentDataVec::<OutputAttachment>::new();
let mut attachment_width = None;
let mut attachment_height = None;
let mut valid_attachment = true;
let context = {
use hal::device::Device as _;
@@ -568,6 +574,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.map_err(|_| RenderPassError::InvalidAttachment(at.attachment))?;
add_view(view)?;
valid_attachment &= *attachment_width.get_or_insert(view.extent.width)
== view.extent.width
&& *attachment_height.get_or_insert(view.extent.height)
== view.extent.height;
let layouts = match view.inner {
TextureViewInner::Native { ref source_id, .. } => {
let previous_use = base_trackers
@@ -623,6 +634,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
colors.push((color_at, hal::image::Layout::ColorAttachmentOptimal));
}
if !valid_attachment {
Err(RenderPassError::MismatchAttachments)?
}
for resolve_target in color_attachments.iter().flat_map(|at| at.resolve_target) {
let view = trackers
.views
@@ -1198,6 +1213,15 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
depth_max,
} => {
use std::{convert::TryFrom, i16};
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
{
Err(RenderCommandError::InvalidViewport)?
}
let r = hal::pso::Rect {
x: i16::try_from(rect.x.round() as i64).unwrap_or(0),
y: i16::try_from(rect.y.round() as i64).unwrap_or(0),
@@ -1249,6 +1273,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
RenderCommand::SetScissor(ref rect) => {
use std::{convert::TryFrom, i16};
if rect.w == 0
|| rect.h == 0
|| rect.x + rect.w > attachment_width.unwrap()
|| rect.y + rect.h > attachment_height.unwrap()
{
Err(RenderCommandError::InvalidScissorRect)?
}
let r = hal::pso::Rect {
x: i16::try_from(rect.x).unwrap_or(0),
y: i16::try_from(rect.y).unwrap_or(0),
+10 -5
View File
@@ -39,6 +39,8 @@ pub enum TransferError {
InvalidBuffer(BufferId),
#[error("texture {0:?} is invalid")]
InvalidTexture(TextureId),
#[error("Source and destination cannot be the same buffer")]
SameSourceDestinationBuffer,
#[error("source buffer/texture is missing the `COPY_SRC` usage flag")]
MissingCopySrcUsageFlag,
#[error("destination buffer/texture is missing the `COPY_DST` usage flag")]
@@ -295,6 +297,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
) -> Result<(), CopyError> {
span!(_guard, INFO, "CommandEncoder::copy_buffer_to_buffer");
if source == destination {
Err(TransferError::SameSourceDestinationBuffer)?
}
let hub = B::hub(self);
let mut token = Token::root();
@@ -317,11 +322,6 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
None => (),
}
if size == 0 {
tracing::trace!("Ignoring copy_buffer_to_buffer of size 0");
return Ok(());
}
let (src_buffer, src_pending) = cmd_buf
.trackers
.buffers
@@ -371,6 +371,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
})?
}
if size == 0 {
tracing::trace!("Ignoring copy_buffer_to_buffer of size 0");
return Ok(());
}
let region = hal::command::BufferCopy {
src: source_offset,
dst: destination_offset,