summaryrefslogtreecommitdiffstats
path: root/third_party/rust/wgpu-core/src/command/clear.rs
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/wgpu-core/src/command/clear.rs')
-rw-r--r--third_party/rust/wgpu-core/src/command/clear.rs45
1 files changed, 26 insertions, 19 deletions
diff --git a/third_party/rust/wgpu-core/src/command/clear.rs b/third_party/rust/wgpu-core/src/command/clear.rs
index 2569fea1a4..e404fabb14 100644
--- a/third_party/rust/wgpu-core/src/command/clear.rs
+++ b/third_party/rust/wgpu-core/src/command/clear.rs
@@ -39,6 +39,11 @@ pub enum ClearError {
UnalignedFillSize(BufferAddress),
#[error("Buffer offset {0:?} is not a multiple of `COPY_BUFFER_ALIGNMENT`")]
UnalignedBufferOffset(BufferAddress),
+ #[error("Clear starts at offset {start_offset} with size of {requested_size}, but these added together exceed `u64::MAX`")]
+ OffsetPlusSizeExceeds64BitBounds {
+ start_offset: BufferAddress,
+ requested_size: BufferAddress,
+ },
#[error("Clear of {start_offset}..{end_offset} would end up overrunning the bounds of the buffer of size {buffer_size}")]
BufferOverrun {
start_offset: BufferAddress,
@@ -117,25 +122,27 @@ impl Global {
if offset % wgt::COPY_BUFFER_ALIGNMENT != 0 {
return Err(ClearError::UnalignedBufferOffset(offset));
}
- if let Some(size) = size {
- if size % wgt::COPY_BUFFER_ALIGNMENT != 0 {
- return Err(ClearError::UnalignedFillSize(size));
- }
- let destination_end_offset = offset + size;
- if destination_end_offset > dst_buffer.size {
- return Err(ClearError::BufferOverrun {
+
+ let size = size.unwrap_or(dst_buffer.size.saturating_sub(offset));
+ if size % wgt::COPY_BUFFER_ALIGNMENT != 0 {
+ return Err(ClearError::UnalignedFillSize(size));
+ }
+ let end_offset =
+ offset
+ .checked_add(size)
+ .ok_or(ClearError::OffsetPlusSizeExceeds64BitBounds {
start_offset: offset,
- end_offset: destination_end_offset,
- buffer_size: dst_buffer.size,
- });
- }
+ requested_size: size,
+ })?;
+ if end_offset > dst_buffer.size {
+ return Err(ClearError::BufferOverrun {
+ start_offset: offset,
+ end_offset,
+ buffer_size: dst_buffer.size,
+ });
}
- let end = match size {
- Some(size) => offset + size,
- None => dst_buffer.size,
- };
- if offset == end {
+ if offset == end_offset {
log::trace!("Ignoring fill_buffer of size 0");
return Ok(());
}
@@ -144,7 +151,7 @@ impl Global {
cmd_buf_data.buffer_memory_init_actions.extend(
dst_buffer.initialization_status.read().create_action(
&dst_buffer,
- offset..end,
+ offset..end_offset,
MemoryInitKind::ImplicitlyInitialized,
),
);
@@ -154,7 +161,7 @@ impl Global {
let cmd_buf_raw = cmd_buf_data.encoder.open()?;
unsafe {
cmd_buf_raw.transition_buffers(dst_barrier.into_iter());
- cmd_buf_raw.clear_buffer(dst_raw, offset..end);
+ cmd_buf_raw.clear_buffer(dst_raw, offset..end_offset);
}
Ok(())
}
@@ -366,7 +373,7 @@ fn clear_texture_via_buffer_copies<A: HalApi>(
assert!(
max_rows_per_copy > 0,
"Zero buffer size is too small to fill a single row \
- of a texture with format {:?} and desc {:?}",
+ of a texture with format {:?} and desc {:?}",
texture_desc.format,
texture_desc.size
);