Skip to content

Commit 7dad106

Browse files
authored
Make the command_encoder_clear_buffer's size an Option<BufferAddress> (#4737)
* Make the size parameter of command_encoder_clear_buffer an Option<BufferAddress> * Add a changelog entry
1 parent dec907a commit 7dad106

File tree

9 files changed

+22
-27
lines changed

9 files changed

+22
-27
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ By @gents83 in [#3626](https://github.com/gfx-rs/wgpu/pull/3626) and tnx also to
7474
- Log vulkan validation layer messages during instance creation and destruction: By @exrook in [#4586](https://github.com/gfx-rs/wgpu/pull/4586)
7575
- `TextureFormat::block_size` is deprecated, use `TextureFormat::block_copy_size` instead: By @wumpf in [#4647](https://github.com/gfx-rs/wgpu/pull/4647)
7676
- 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).
77+
- Make the size parameter of `encoder.clear_buffer` an `Option<u64>` instead of `Option<NonZero<u64>>`. By @nical in [#4737](https://github.com/gfx-rs/wgpu/pull/4737)
7778

7879
#### Safe `Surface` creation
7980

deno_webgpu/command_encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ pub fn op_webgpu_command_encoder_clear_buffer(
475475
command_encoder,
476476
destination_resource.1,
477477
offset,
478-
std::num::NonZeroU64::new(size)
478+
Some(size)
479479
))
480480
}
481481

tests/tests/regression/issue_4122.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{num::NonZeroU64, ops::Range};
1+
use std::ops::Range;
22

33
use wgpu_test::{gpu_test, GpuTestConfiguration, TestingContext};
44

@@ -27,11 +27,7 @@ fn fill_test(ctx: &TestingContext, range: Range<u64>, size: u64) -> bool {
2727
label: Some("encoder"),
2828
});
2929

30-
encoder.clear_buffer(
31-
&gpu_buffer,
32-
range.start,
33-
NonZeroU64::new(range.end - range.start),
34-
);
30+
encoder.clear_buffer(&gpu_buffer, range.start, Some(range.end - range.start));
3531
encoder.copy_buffer_to_buffer(&gpu_buffer, 0, &cpu_buffer, 0, size);
3632

3733
ctx.queue.submit(Some(encoder.finish()));

wgpu-core/src/command/clear.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ use crate::{
1616

1717
use hal::CommandEncoder as _;
1818
use thiserror::Error;
19-
use wgt::{
20-
math::align_to, BufferAddress, BufferSize, BufferUsages, ImageSubresourceRange, TextureAspect,
21-
};
19+
use wgt::{math::align_to, BufferAddress, BufferUsages, ImageSubresourceRange, TextureAspect};
2220

2321
/// Error encountered while attempting a clear.
2422
#[derive(Clone, Debug, Error)]
@@ -37,7 +35,7 @@ pub enum ClearError {
3735
#[error("Texture {0:?} can not be cleared")]
3836
NoValidTextureClearMode(TextureId),
3937
#[error("Buffer clear size {0:?} is not a multiple of `COPY_BUFFER_ALIGNMENT`")]
40-
UnalignedFillSize(BufferSize),
38+
UnalignedFillSize(BufferAddress),
4139
#[error("Buffer offset {0:?} is not a multiple of `COPY_BUFFER_ALIGNMENT`")]
4240
UnalignedBufferOffset(BufferAddress),
4341
#[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<G: GlobalIdentityHandlerFactory> Global<G> {
7573
command_encoder_id: CommandEncoderId,
7674
dst: BufferId,
7775
offset: BufferAddress,
78-
size: Option<BufferSize>,
76+
size: Option<BufferAddress>,
7977
) -> Result<(), ClearError> {
8078
profiling::scope!("CommandEncoder::clear_buffer");
8179
log::trace!("CommandEncoder::clear_buffer {dst:?}");
@@ -116,10 +114,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
116114
return Err(ClearError::UnalignedBufferOffset(offset));
117115
}
118116
if let Some(size) = size {
119-
if size.get() % wgt::COPY_BUFFER_ALIGNMENT != 0 {
117+
if size % wgt::COPY_BUFFER_ALIGNMENT != 0 {
120118
return Err(ClearError::UnalignedFillSize(size));
121119
}
122-
let destination_end_offset = offset + size.get();
120+
let destination_end_offset = offset + size;
123121
if destination_end_offset > dst_buffer.size {
124122
return Err(ClearError::BufferOverrun {
125123
start_offset: offset,
@@ -130,7 +128,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
130128
}
131129

132130
let end = match size {
133-
Some(size) => offset + size.get(),
131+
Some(size) => offset + size,
134132
None => dst_buffer.size,
135133
};
136134
if offset == end {

wgpu-core/src/device/trace.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub enum Command {
154154
ClearBuffer {
155155
dst: id::BufferId,
156156
offset: wgt::BufferAddress,
157-
size: Option<wgt::BufferSize>,
157+
size: Option<wgt::BufferAddress>,
158158
},
159159
ClearTexture {
160160
dst: id::TextureId,

wgpu/src/backend/direct.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2059,7 +2059,7 @@ impl crate::Context for Context {
20592059
encoder_data: &Self::CommandEncoderData,
20602060
buffer: &crate::Buffer,
20612061
offset: wgt::BufferAddress,
2062-
size: Option<wgt::BufferSize>,
2062+
size: Option<wgt::BufferAddress>,
20632063
) {
20642064
let global = &self.0;
20652065
if let Err(cause) = wgc::gfx_select!(encoder => global.command_encoder_clear_buffer(

wgpu/src/backend/web.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2446,15 +2446,15 @@ impl crate::context::Context for Context {
24462446
encoder_data: &Self::CommandEncoderData,
24472447
buffer: &crate::Buffer,
24482448
offset: wgt::BufferAddress,
2449-
size: Option<wgt::BufferSize>,
2449+
size: Option<wgt::BufferAddress>,
24502450
) {
24512451
let buffer: &<Context as crate::Context>::BufferData = downcast_ref(buffer.data.as_ref());
24522452
match size {
2453-
Some(size) => encoder_data.0.clear_buffer_with_f64_and_f64(
2454-
&buffer.0,
2455-
offset as f64,
2456-
size.get() as f64,
2457-
),
2453+
Some(size) => {
2454+
encoder_data
2455+
.0
2456+
.clear_buffer_with_f64_and_f64(&buffer.0, offset as f64, size as f64)
2457+
}
24582458
None => encoder_data
24592459
.0
24602460
.clear_buffer_with_f64(&buffer.0, offset as f64),

wgpu/src/context.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ pub trait Context: Debug + WasmNotSendSync + Sized {
494494
encoder_data: &Self::CommandEncoderData,
495495
buffer: &Buffer,
496496
offset: BufferAddress,
497-
size: Option<BufferSize>,
497+
size: Option<BufferAddress>,
498498
);
499499

500500
fn command_encoder_insert_debug_marker(
@@ -1570,7 +1570,7 @@ pub(crate) trait DynContext: Debug + WasmNotSendSync {
15701570
encoder_data: &crate::Data,
15711571
buffer: &Buffer,
15721572
offset: BufferAddress,
1573-
size: Option<BufferSize>,
1573+
size: Option<BufferAddress>,
15741574
);
15751575

15761576
fn command_encoder_insert_debug_marker(
@@ -2914,7 +2914,7 @@ where
29142914
encoder_data: &crate::Data,
29152915
buffer: &Buffer,
29162916
offset: BufferAddress,
2917-
size: Option<BufferSize>,
2917+
size: Option<BufferAddress>,
29182918
) {
29192919
let encoder = <T::CommandEncoderId>::from(*encoder);
29202920
let encoder_data = downcast_ref(encoder_data);

wgpu/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3643,7 +3643,7 @@ impl CommandEncoder {
36433643
&mut self,
36443644
buffer: &Buffer,
36453645
offset: BufferAddress,
3646-
size: Option<BufferSize>,
3646+
size: Option<BufferAddress>,
36473647
) {
36483648
DynContext::command_encoder_clear_buffer(
36493649
&*self.context,

0 commit comments

Comments
 (0)