From f7ed0de35ea01352f14a1b955f0ecf6a48a79d5c Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Tue, 21 Nov 2023 15:22:02 +0100 Subject: [PATCH] Make the size parameter of command_encoder_clear_buffer an Option --- deno_webgpu/command_encoder.rs | 2 +- tests/tests/regression/issue_4122.rs | 8 ++------ wgpu-core/src/command/clear.rs | 14 ++++++-------- wgpu-core/src/device/trace.rs | 2 +- wgpu/src/backend/direct.rs | 2 +- wgpu/src/backend/web.rs | 4 ++-- wgpu/src/context.rs | 6 +++--- wgpu/src/lib.rs | 2 +- 8 files changed, 17 insertions(+), 23 deletions(-) diff --git a/deno_webgpu/command_encoder.rs b/deno_webgpu/command_encoder.rs index 60de26eaf97..73fe2dd9a5c 100644 --- a/deno_webgpu/command_encoder.rs +++ b/deno_webgpu/command_encoder.rs @@ -475,7 +475,7 @@ pub fn op_webgpu_command_encoder_clear_buffer( command_encoder, destination_resource.1, offset, - std::num::NonZeroU64::new(size) + Some(size), )) } diff --git a/tests/tests/regression/issue_4122.rs b/tests/tests/regression/issue_4122.rs index c6f7afbddea..b3301610bed 100644 --- a/tests/tests/regression/issue_4122.rs +++ b/tests/tests/regression/issue_4122.rs @@ -1,4 +1,4 @@ -use std::{num::NonZeroU64, ops::Range}; +use std::ops::Range; use wgpu_test::{gpu_test, GpuTestConfiguration, TestingContext}; @@ -27,11 +27,7 @@ fn fill_test(ctx: &TestingContext, range: Range, size: u64) -> bool { label: Some("encoder"), }); - encoder.clear_buffer( - &gpu_buffer, - range.start, - NonZeroU64::new(range.end - range.start), - ); + encoder.clear_buffer(&gpu_buffer, range.start, Some(range.end - range.start)); encoder.copy_buffer_to_buffer(&gpu_buffer, 0, &cpu_buffer, 0, size); ctx.queue.submit(Some(encoder.finish())); diff --git a/wgpu-core/src/command/clear.rs b/wgpu-core/src/command/clear.rs index b702c25c67f..2ee823a0159 100644 --- a/wgpu-core/src/command/clear.rs +++ b/wgpu-core/src/command/clear.rs @@ -16,9 +16,7 @@ use crate::{ use hal::CommandEncoder as _; use thiserror::Error; -use wgt::{ - math::align_to, BufferAddress, BufferSize, BufferUsages, ImageSubresourceRange, TextureAspect, -}; +use wgt::{math::align_to, BufferAddress, BufferUsages, ImageSubresourceRange, TextureAspect}; /// Error encountered while attempting a clear. #[derive(Clone, Debug, Error)] @@ -37,7 +35,7 @@ pub enum ClearError { #[error("Texture {0:?} can not be cleared")] NoValidTextureClearMode(TextureId), #[error("Buffer clear size {0:?} is not a multiple of `COPY_BUFFER_ALIGNMENT`")] - UnalignedFillSize(BufferSize), + UnalignedFillSize(BufferAddress), #[error("Buffer offset {0:?} is not a multiple of `COPY_BUFFER_ALIGNMENT`")] UnalignedBufferOffset(BufferAddress), #[error("Clear of {start_offset}..{end_offset} would end up overrunning the bounds of the buffer of size {buffer_size}")] @@ -75,7 +73,7 @@ impl Global { command_encoder_id: CommandEncoderId, dst: BufferId, offset: BufferAddress, - size: Option, + size: Option, ) -> Result<(), ClearError> { profiling::scope!("CommandEncoder::clear_buffer"); log::trace!("CommandEncoder::clear_buffer {dst:?}"); @@ -116,10 +114,10 @@ impl Global { return Err(ClearError::UnalignedBufferOffset(offset)); } if let Some(size) = size { - if size.get() % wgt::COPY_BUFFER_ALIGNMENT != 0 { + if size % wgt::COPY_BUFFER_ALIGNMENT != 0 { return Err(ClearError::UnalignedFillSize(size)); } - let destination_end_offset = offset + size.get(); + let destination_end_offset = offset + size; if destination_end_offset > dst_buffer.size { return Err(ClearError::BufferOverrun { start_offset: offset, @@ -130,7 +128,7 @@ impl Global { } let end = match size { - Some(size) => offset + size.get(), + Some(size) => offset + size, None => dst_buffer.size, }; if offset == end { diff --git a/wgpu-core/src/device/trace.rs b/wgpu-core/src/device/trace.rs index ab5806bb903..315b7e8e849 100644 --- a/wgpu-core/src/device/trace.rs +++ b/wgpu-core/src/device/trace.rs @@ -154,7 +154,7 @@ pub enum Command { ClearBuffer { dst: id::BufferId, offset: wgt::BufferAddress, - size: Option, + size: Option, }, ClearTexture { dst: id::TextureId, diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs index c6b7cafc08a..763ae4780dc 100644 --- a/wgpu/src/backend/direct.rs +++ b/wgpu/src/backend/direct.rs @@ -2059,7 +2059,7 @@ impl crate::Context for Context { encoder_data: &Self::CommandEncoderData, buffer: &crate::Buffer, offset: wgt::BufferAddress, - size: Option, + size: Option, ) { let global = &self.0; if let Err(cause) = wgc::gfx_select!(encoder => global.command_encoder_clear_buffer( diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index 9cdb7dca759..5cbd6fa1fba 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -2446,14 +2446,14 @@ impl crate::context::Context for Context { encoder_data: &Self::CommandEncoderData, buffer: &crate::Buffer, offset: wgt::BufferAddress, - size: Option, + size: Option, ) { let buffer: &::BufferData = downcast_ref(buffer.data.as_ref()); match size { Some(size) => encoder_data.0.clear_buffer_with_f64_and_f64( &buffer.0, offset as f64, - size.get() as f64, + size as f64, ), None => encoder_data .0 diff --git a/wgpu/src/context.rs b/wgpu/src/context.rs index 1a1ad242b1a..12da5b2a951 100644 --- a/wgpu/src/context.rs +++ b/wgpu/src/context.rs @@ -494,7 +494,7 @@ pub trait Context: Debug + WasmNotSendSync + Sized { encoder_data: &Self::CommandEncoderData, buffer: &Buffer, offset: BufferAddress, - size: Option, + size: Option, ); fn command_encoder_insert_debug_marker( @@ -1570,7 +1570,7 @@ pub(crate) trait DynContext: Debug + WasmNotSendSync { encoder_data: &crate::Data, buffer: &Buffer, offset: BufferAddress, - size: Option, + size: Option, ); fn command_encoder_insert_debug_marker( @@ -2914,7 +2914,7 @@ where encoder_data: &crate::Data, buffer: &Buffer, offset: BufferAddress, - size: Option, + size: Option, ) { let encoder = ::from(*encoder); let encoder_data = downcast_ref(encoder_data); diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index ffab396c858..9c2adff1e53 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -3643,7 +3643,7 @@ impl CommandEncoder { &mut self, buffer: &Buffer, offset: BufferAddress, - size: Option, + size: Option, ) { DynContext::command_encoder_clear_buffer( &*self.context,