Skip to content

Make wgpu-core's copy_buffer_to_buffer size parameter optional #7659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deno_webgpu/command_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl GPUCommandEncoder {
#[webidl(options(enforce_range = true))] source_offset: u64,
#[webidl] destination: Ptr<GPUBuffer>,
#[webidl(options(enforce_range = true))] destination_offset: u64,
#[webidl(options(enforce_range = true))] size: u64,
#[webidl(options(enforce_range = true))] size: Option<u64>,
) {
let err = self
.instance
Expand Down
8 changes: 6 additions & 2 deletions wgpu-core/src/command/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ impl Global {
source_offset: BufferAddress,
destination: BufferId,
destination_offset: BufferAddress,
size: BufferAddress,
size: Option<BufferAddress>,
) -> Result<(), CopyError> {
profiling::scope!("CommandEncoder::copy_buffer_to_buffer");
api_log!(
Expand Down Expand Up @@ -598,6 +598,11 @@ impl Global {
.map_err(TransferError::MissingBufferUsage)?;
let dst_barrier = dst_pending.map(|pending| pending.into_hal(&dst_buffer, &snatch_guard));

let (size, source_end_offset) = match size {
Some(size) => (size, source_offset + size),
None => (src_buffer.size - source_offset, src_buffer.size),
};

if size % wgt::COPY_BUFFER_ALIGNMENT != 0 {
return Err(TransferError::UnalignedCopySize(size).into());
}
Expand Down Expand Up @@ -628,7 +633,6 @@ impl Global {
}
}

let source_end_offset = source_offset + size;
let destination_end_offset = destination_offset + size;
if source_end_offset > src_buffer.size {
return Err(TransferError::BufferOverrun {
Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/src/device/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pub enum Command {
src_offset: wgt::BufferAddress,
dst: id::BufferId,
dst_offset: wgt::BufferAddress,
size: wgt::BufferAddress,
size: Option<wgt::BufferAddress>,
},
CopyBufferToTexture {
src: crate::command::TexelCopyBufferInfo,
Expand Down
4 changes: 2 additions & 2 deletions wgpu/src/api/command_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ impl CommandEncoder {
source_offset: BufferAddress,
destination: &Buffer,
destination_offset: BufferAddress,
copy_size: BufferAddress,
copy_size: impl Into<Option<BufferAddress>>,
) {
self.inner.copy_buffer_to_buffer(
&source.inner,
source_offset,
&destination.inner,
destination_offset,
copy_size,
copy_size.into(),
);
}

Expand Down
31 changes: 21 additions & 10 deletions wgpu/src/backend/webgpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2809,20 +2809,31 @@ impl dispatch::CommandEncoderInterface for WebCommandEncoder {
source_offset: crate::BufferAddress,
destination: &dispatch::DispatchBuffer,
destination_offset: crate::BufferAddress,
copy_size: crate::BufferAddress,
copy_size: Option<crate::BufferAddress>,
) {
let source = source.as_webgpu();
let destination = destination.as_webgpu();

self.inner
.copy_buffer_to_buffer_with_f64_and_f64_and_f64(
&source.inner,
source_offset as f64,
&destination.inner,
destination_offset as f64,
copy_size as f64,
)
.unwrap();
if let Some(size) = copy_size {
self.inner
.copy_buffer_to_buffer_with_f64_and_f64_and_f64(
&source.inner,
source_offset as f64,
&destination.inner,
destination_offset as f64,
size as f64,
)
.unwrap();
} else {
self.inner
.copy_buffer_to_buffer_with_f64_and_f64(
&source.inner,
source_offset as f64,
&destination.inner,
destination_offset as f64,
)
.unwrap();
}
}

fn copy_buffer_to_texture(
Expand Down
70 changes: 69 additions & 1 deletion wgpu/src/backend/webgpu/webgpu_sys/gen_GpuCommandEncoder.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion wgpu/src/backend/wgpu_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2217,7 +2217,7 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder {
source_offset: crate::BufferAddress,
destination: &dispatch::DispatchBuffer,
destination_offset: crate::BufferAddress,
copy_size: crate::BufferAddress,
copy_size: Option<crate::BufferAddress>,
) {
let source = source.as_core();
let destination = destination.as_core();
Expand Down
2 changes: 1 addition & 1 deletion wgpu/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ pub trait CommandEncoderInterface: CommonTraits {
source_offset: crate::BufferAddress,
destination: &DispatchBuffer,
destination_offset: crate::BufferAddress,
copy_size: crate::BufferAddress,
copy_size: Option<crate::BufferAddress>,
);
fn copy_buffer_to_texture(
&self,
Expand Down