mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
Improve validation in b2b copies and RenderCommands
This commit is contained in:
parent
0bb6bb8647
commit
f266431f24
@ -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)]
|
||||
|
||||
@ -466,6 +466,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
}
|
||||
let mut output_attachments = AttachmentDataVec::<OutputAttachment>::new();
|
||||
|
||||
let mut attachment_width = std::u32::MAX;
|
||||
let mut attachment_height = std::u32::MAX;
|
||||
|
||||
let context = {
|
||||
use hal::device::Device as _;
|
||||
|
||||
@ -568,6 +571,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
.map_err(|_| RenderPassError::InvalidAttachment(at.attachment))?;
|
||||
add_view(view)?;
|
||||
|
||||
attachment_width = attachment_width.min(view.extent.width);
|
||||
attachment_height = attachment_height.min(view.extent.height);
|
||||
|
||||
let layouts = match view.inner {
|
||||
TextureViewInner::Native { ref source_id, .. } => {
|
||||
let previous_use = base_trackers
|
||||
@ -1198,6 +1204,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 +1264,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
|
||||
|| rect.y + rect.h > attachment_height
|
||||
{
|
||||
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),
|
||||
|
||||
@ -46,6 +46,8 @@ pub enum TransferError {
|
||||
InvalidBuffer(BufferId),
|
||||
#[error("texture {0:?} is invalid")]
|
||||
InvalidTexture(TextureId),
|
||||
#[error("Source and destination cannot be the same buffer")]
|
||||
AttemptToCopyWithinBuffer,
|
||||
#[error("source buffer/texture is missing the `COPY_SRC` usage flag")]
|
||||
MissingCopySrcUsageFlag,
|
||||
#[error("destination buffer/texture is missing the `COPY_DST` usage flag")]
|
||||
@ -302,6 +304,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
) -> Result<(), CopyError> {
|
||||
span!(_guard, INFO, "CommandEncoder::copy_buffer_to_buffer");
|
||||
|
||||
if source == destination {
|
||||
Err(TransferError::AttemptToCopyWithinBuffer)?
|
||||
}
|
||||
let hub = B::hub(self);
|
||||
let mut token = Token::root();
|
||||
|
||||
@ -324,11 +329,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
|
||||
@ -378,6 +378,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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user