From 7dad1060394236573bd5fd0f6a0f04c95ebf02e2 Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Wed, 22 Nov 2023 11:42:34 +0100 Subject: [PATCH] Make the command_encoder_clear_buffer's size an Option (#4737) * Make the size parameter of command_encoder_clear_buffer an Option * Add a changelog entry --- CHANGELOG.md | 1 + 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 | 12 ++++++------ wgpu/src/context.rs | 6 +++--- wgpu/src/lib.rs | 2 +- 9 files changed, 22 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7519428f38..792548fd89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,7 @@ By @gents83 in [#3626](https://github.com/gfx-rs/wgpu/pull/3626) and tnx also to - Log vulkan validation layer messages during instance creation and destruction: By @exrook in [#4586](https://github.com/gfx-rs/wgpu/pull/4586) - `TextureFormat::block_size` is deprecated, use `TextureFormat::block_copy_size` instead: By @wumpf in [#4647](https://github.com/gfx-rs/wgpu/pull/4647) - Rename of `DispatchIndirect`, `DrawIndexedIndirect`, and `DrawIndirect` types in the `wgpu::util` module to `DispatchIndirectArgs`, `DrawIndexedIndirectArgs`, and `DrawIndirectArgs`. By @cwfitzgerald in [#4723](https://github.com/gfx-rs/wgpu/pull/4723). +- Make the size parameter of `encoder.clear_buffer` an `Option` instead of `Option>`. By @nical in [#4737](https://github.com/gfx-rs/wgpu/pull/4737) #### Safe `Surface` creation diff --git a/deno_webgpu/command_encoder.rs b/deno_webgpu/command_encoder.rs index 60de26eaf9..7079fd96cf 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 c6f7afbdde..b3301610be 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 b702c25c67..2ee823a015 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 ab5806bb90..315b7e8e84 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 c6b7cafc08..763ae4780d 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 9cdb7dca75..2830ffc3f1 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -2446,15 +2446,15 @@ 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, - ), + Some(size) => { + encoder_data + .0 + .clear_buffer_with_f64_and_f64(&buffer.0, offset as f64, size as f64) + } None => encoder_data .0 .clear_buffer_with_f64(&buffer.0, offset as f64), diff --git a/wgpu/src/context.rs b/wgpu/src/context.rs index 1a1ad242b1..12da5b2a95 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 73f13fb965..f6a7d67f14 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,