Skip to content

Commit 3cca5f8

Browse files
Make the copy_buffer_to_buffer size parameter optional (#7659)
* Make wgpu-core's copy_buffer_to_buffer `size` parameter optional * Make the copy size optional in more places * Fix for webgpu backend * [deno_webgpu] Support additional copyBufferToBuffer signatures * Add changelog entry * Add copyBufferToBuffer tests to CTS test list (This doesn't actually enable the tests for the new overloads, because of a different error reporting issue that affects many CTS tests including these. But if you run the tests for the new overloads manually, before and after the fix, you can see that the behavior has changed.) * Reproducible formula for vendoring modified webgpu-sys Commit the updated vendor command in all the files for consistency.
1 parent 8d3ade9 commit 3cca5f8

File tree

138 files changed

+322
-155
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+322
-155
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ Naga now infers the correct binding layout when a resource appears only in an as
102102

103103
- Use highest SPIR-V version supported by Vulkan API version. By @robamler in [#7595](https://github.com/gfx-rs/wgpu/pull/7595)
104104

105+
#### WebGPU
106+
107+
- The type of the `size` parameter to `copy_buffer_to_buffer` has changed from `BufferAddress` to `impl Into<Option<BufferAddress>>`. This achieves the spec-defined behavior of the value being optional, while still accepting existing calls without changes. By @andyleiserson in [#7659](https://github.com/gfx-rs/wgpu/pull/7659).
108+
105109
### Bug Fixes
106110

107111
#### Naga

cts_runner/test.lst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
unittests:*
22
webgpu:api,operation,command_buffer,basic:*
3+
webgpu:api,operation,command_buffer,copyBufferToBuffer:single:newSig=false;*
4+
// https://github.com/gfx-rs/wgpu/issues/7391
5+
//FAIL: webgpu:api,operation,command_buffer,copyBufferToBuffer:single:newSig=true;*
6+
webgpu:api,operation,command_buffer,copyBufferToBuffer:state_transitions:*
7+
webgpu:api,operation,command_buffer,copyBufferToBuffer:copy_order:*
38
webgpu:api,operation,compute,basic:memcpy:*
49
//FAIL: webgpu:api,operation,compute,basic:large_dispatch:*
510
webgpu:api,operation,device,lost:*

deno_webgpu/command_encoder.rs

Lines changed: 75 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ use std::cell::RefCell;
55

66
use deno_core::cppgc::Ptr;
77
use deno_core::op2;
8+
use deno_core::v8;
9+
use deno_core::webidl::{IntOptions, WebIdlConverter, WebIdlError};
810
use deno_core::GarbageCollected;
911
use deno_core::WebIDL;
1012
use deno_error::JsErrorBox;
1113
use wgpu_core::command::PassChannel;
12-
use wgpu_types::TexelCopyBufferInfo;
14+
use wgpu_types::{BufferAddress, TexelCopyBufferInfo};
1315

1416
use crate::buffer::GPUBuffer;
1517
use crate::command_buffer::GPUCommandBuffer;
@@ -171,15 +173,78 @@ impl GPUCommandEncoder {
171173
}
172174
}
173175

174-
#[required(5)]
175-
fn copy_buffer_to_buffer(
176+
#[required(2)]
177+
fn copy_buffer_to_buffer<'a>(
176178
&self,
179+
scope: &mut v8::HandleScope<'a>,
177180
#[webidl] source: Ptr<GPUBuffer>,
178-
#[webidl(options(enforce_range = true))] source_offset: u64,
179-
#[webidl] destination: Ptr<GPUBuffer>,
180-
#[webidl(options(enforce_range = true))] destination_offset: u64,
181-
#[webidl(options(enforce_range = true))] size: u64,
182-
) {
181+
arg2: v8::Local<'a, v8::Value>,
182+
arg3: v8::Local<'a, v8::Value>,
183+
arg4: v8::Local<'a, v8::Value>,
184+
arg5: v8::Local<'a, v8::Value>,
185+
) -> Result<(), WebIdlError> {
186+
let prefix = "Failed to execute 'GPUCommandEncoder.copyBufferToBuffer'";
187+
let int_options = IntOptions {
188+
clamp: false,
189+
enforce_range: true,
190+
};
191+
192+
let source_offset: BufferAddress;
193+
let destination: Ptr<GPUBuffer>;
194+
let destination_offset: BufferAddress;
195+
let size: Option<BufferAddress>;
196+
// Note that the last argument to either overload of `copy_buffer_to_buffer`
197+
// is optional, so `arg5.is_undefined()` would not work here.
198+
if arg4.is_undefined() {
199+
// 3-argument overload
200+
source_offset = 0;
201+
destination = Ptr::<GPUBuffer>::convert(
202+
scope,
203+
arg2,
204+
Cow::Borrowed(prefix),
205+
(|| Cow::Borrowed("destination")).into(),
206+
&(),
207+
)?;
208+
destination_offset = 0;
209+
size = <Option<u64>>::convert(
210+
scope,
211+
arg3,
212+
Cow::Borrowed(prefix),
213+
(|| Cow::Borrowed("size")).into(),
214+
&int_options,
215+
)?;
216+
} else {
217+
// 5-argument overload
218+
source_offset = u64::convert(
219+
scope,
220+
arg2,
221+
Cow::Borrowed(prefix),
222+
(|| Cow::Borrowed("sourceOffset")).into(),
223+
&int_options,
224+
)?;
225+
destination = Ptr::<GPUBuffer>::convert(
226+
scope,
227+
arg3,
228+
Cow::Borrowed(prefix),
229+
(|| Cow::Borrowed("destination")).into(),
230+
&(),
231+
)?;
232+
destination_offset = u64::convert(
233+
scope,
234+
arg4,
235+
Cow::Borrowed(prefix),
236+
(|| Cow::Borrowed("destinationOffset")).into(),
237+
&int_options,
238+
)?;
239+
size = <Option<u64>>::convert(
240+
scope,
241+
arg5,
242+
Cow::Borrowed(prefix),
243+
(|| Cow::Borrowed("size")).into(),
244+
&int_options,
245+
)?;
246+
}
247+
183248
let err = self
184249
.instance
185250
.command_encoder_copy_buffer_to_buffer(
@@ -193,6 +258,8 @@ impl GPUCommandEncoder {
193258
.err();
194259

195260
self.error_handler.push_error(err);
261+
262+
Ok(())
196263
}
197264

198265
#[required(3)]

wgpu-core/src/command/transfer.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ impl Global {
532532
source_offset: BufferAddress,
533533
destination: BufferId,
534534
destination_offset: BufferAddress,
535-
size: BufferAddress,
535+
size: Option<BufferAddress>,
536536
) -> Result<(), CopyError> {
537537
profiling::scope!("CommandEncoder::copy_buffer_to_buffer");
538538
api_log!(
@@ -598,6 +598,11 @@ impl Global {
598598
.map_err(TransferError::MissingBufferUsage)?;
599599
let dst_barrier = dst_pending.map(|pending| pending.into_hal(&dst_buffer, &snatch_guard));
600600

601+
let (size, source_end_offset) = match size {
602+
Some(size) => (size, source_offset + size),
603+
None => (src_buffer.size - source_offset, src_buffer.size),
604+
};
605+
601606
if size % wgt::COPY_BUFFER_ALIGNMENT != 0 {
602607
return Err(TransferError::UnalignedCopySize(size).into());
603608
}
@@ -628,7 +633,6 @@ impl Global {
628633
}
629634
}
630635

631-
let source_end_offset = source_offset + size;
632636
let destination_end_offset = destination_offset + size;
633637
if source_end_offset > src_buffer.size {
634638
return Err(TransferError::BufferOverrun {

wgpu-core/src/device/trace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ pub enum Command {
151151
src_offset: wgt::BufferAddress,
152152
dst: id::BufferId,
153153
dst_offset: wgt::BufferAddress,
154-
size: wgt::BufferAddress,
154+
size: Option<wgt::BufferAddress>,
155155
},
156156
CopyBufferToTexture {
157157
src: crate::command::TexelCopyBufferInfo,

wgpu/src/api/command_encoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ impl CommandEncoder {
116116
source_offset: BufferAddress,
117117
destination: &Buffer,
118118
destination_offset: BufferAddress,
119-
copy_size: BufferAddress,
119+
copy_size: impl Into<Option<BufferAddress>>,
120120
) {
121121
self.inner.copy_buffer_to_buffer(
122122
&source.inner,
123123
source_offset,
124124
&destination.inner,
125125
destination_offset,
126-
copy_size,
126+
copy_size.into(),
127127
);
128128
}
129129

wgpu/src/backend/webgpu.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2813,20 +2813,31 @@ impl dispatch::CommandEncoderInterface for WebCommandEncoder {
28132813
source_offset: crate::BufferAddress,
28142814
destination: &dispatch::DispatchBuffer,
28152815
destination_offset: crate::BufferAddress,
2816-
copy_size: crate::BufferAddress,
2816+
copy_size: Option<crate::BufferAddress>,
28172817
) {
28182818
let source = source.as_webgpu();
28192819
let destination = destination.as_webgpu();
28202820

2821-
self.inner
2822-
.copy_buffer_to_buffer_with_f64_and_f64_and_f64(
2823-
&source.inner,
2824-
source_offset as f64,
2825-
&destination.inner,
2826-
destination_offset as f64,
2827-
copy_size as f64,
2828-
)
2829-
.unwrap();
2821+
if let Some(size) = copy_size {
2822+
self.inner
2823+
.copy_buffer_to_buffer_with_f64_and_f64_and_f64(
2824+
&source.inner,
2825+
source_offset as f64,
2826+
&destination.inner,
2827+
destination_offset as f64,
2828+
size as f64,
2829+
)
2830+
.unwrap();
2831+
} else {
2832+
self.inner
2833+
.copy_buffer_to_buffer_with_f64_and_f64(
2834+
&source.inner,
2835+
source_offset as f64,
2836+
&destination.inner,
2837+
destination_offset as f64,
2838+
)
2839+
.unwrap();
2840+
}
28302841
}
28312842

28322843
fn copy_buffer_to_texture(

wgpu/src/backend/webgpu/webgpu_sys/gen_Gpu.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wgpu/src/backend/webgpu/webgpu_sys/gen_GpuAdapter.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wgpu/src/backend/webgpu/webgpu_sys/gen_GpuAdapterInfo.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)