Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,26 @@ The **`copyBufferToBuffer()`** method of the
## Syntax

```js-nolint
copyBufferToBuffer(source, destination)
Copy link
Collaborator

@hamishwillee hamishwillee Jun 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec says description does not indicate that size is optional in https://gpuweb.github.io/gpuweb/#commands-buffer-copies , but does indicate it in the IDL https://gpuweb.github.io/gpuweb/#gpucommandencoder

So, I think that there are two options, one for copying the whole buffer from 0, and one for copying part of the buffer from 0. I think the note below is still fine though, because it refers to copying the whole buffer.
Might be worth some comment on this case with size though.

Suggested change
copyBufferToBuffer(source, destination)
copyBufferToBuffer(source, destination)
copyBufferToBuffer(source, destination, size)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good call. I had grokked this, but I wasn't sure it needed to be said. I think you are right, though; it's good to be explicit about all possible cases.

I've added the case to the syntax and added an explanation to the note.

I also tested this case to make sure it works.

copyBufferToBuffer(source, sourceOffset, destination, destinationOffset, size)
```

### Parameters

- `source`
- : The {{domxref("GPUBuffer")}} to copy from.
- `sourceOffset`
- `sourceOffset` {{optional_inline}}
- : The offset, in bytes, into the `source` to begin copying from.
- `destination`
- : The {{domxref("GPUBuffer")}} to copy to.
- `destinationOffset`
- `destinationOffset` {{optional_inline}}
- : The offset, in bytes, into the `destination` to begin copying to.
- `size`
- `size` {{optional_inline}}
- : The number of bytes to copy.

> [!NOTE]
> The `sourceOffset`, `destinationOffset`, and `size` can be omitted if you are copying the entire source buffer to the destination buffer.

### Return value

None ({{jsxref("Undefined")}}).
Expand Down Expand Up @@ -82,6 +86,9 @@ commandEncoder.copyBufferToBuffer(
BUFFER_SIZE,
);

// Since we are copying the entire buffer, this can be shortened to
// commandEncoder.copyBufferToBuffer(output, stagingBuffer);

// …
```

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/gpudevice/createbindgroup/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ createBindGroup(descriptor)
- `GPUBufferBinding` (which wraps a {{domxref("GPUBuffer")}}; see [GPUBufferBinding objects](#gpubufferbinding_objects) for a definition)
- {{domxref("GPUExternalTexture")}}
- {{domxref("GPUSampler")}}
- {{domxref("GPUTextureView")}}
- {{domxref("GPUTextureView")}}; can be used in place of a `GPUExternalTexture` provided it is compatible (a 2D format with a single subresource, that is, [`dimension: "2d"`](/en-US/docs/Web/API/GPUTexture/createView#dimension)).
- `label` {{optional_inline}}
- : A string providing a label that can be used to identify the object, for example in {{domxref("GPUError")}} messages or console warnings.
- `layout`
Expand Down