diff --git a/files/en-us/web/api/gpucommandencoder/copybuffertobuffer/index.md b/files/en-us/web/api/gpucommandencoder/copybuffertobuffer/index.md index 29603616968f6e1..5aaff1b343bcb65 100644 --- a/files/en-us/web/api/gpucommandencoder/copybuffertobuffer/index.md +++ b/files/en-us/web/api/gpucommandencoder/copybuffertobuffer/index.md @@ -16,6 +16,8 @@ The **`copyBufferToBuffer()`** method of the ## Syntax ```js-nolint +copyBufferToBuffer(source, destination) +copyBufferToBuffer(source, destination, size) copyBufferToBuffer(source, sourceOffset, destination, destinationOffset, size) ``` @@ -23,15 +25,18 @@ copyBufferToBuffer(source, sourceOffset, destination, destinationOffset, size) - `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` and `destinationOffset` can be omitted if you are copying part of the source buffer at a `0` offset in both the source and destination buffers. 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")}}). @@ -49,14 +54,14 @@ The following criteria must be met when calling **`copyBufferToBuffer()`**, othe ## Examples -In our [basic compute demo](https://mdn.github.io/dom-examples/webgpu-compute-demo/), we use `copyBufferToBuffer()` to copy the contents of our `output` buffer to the `stagingBuffer`. +In our [basic compute demo](https://mdn.github.io/dom-examples/webgpu-compute-demo/), we use `copyBufferToBuffer()` to copy the contents of our `outputBuffer` to the `stagingBuffer`. ```js // … // Create an output buffer to read GPU calculations to, and a staging buffer to be mapped for JavaScript access -const output = device.createBuffer({ +const outputBuffer = device.createBuffer({ size: BUFFER_SIZE, usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC, }); @@ -75,13 +80,16 @@ const commandEncoder = device.createCommandEncoder(); // Copy output buffer to staging buffer commandEncoder.copyBufferToBuffer( - output, + outputBuffer, 0, // Source offset stagingBuffer, 0, // Destination offset BUFFER_SIZE, ); +// Since we are copying the entire buffer, this can be shortened to +// commandEncoder.copyBufferToBuffer(outputBuffer, stagingBuffer); + // … ``` diff --git a/files/en-us/web/api/gpudevice/createbindgroup/index.md b/files/en-us/web/api/gpudevice/createbindgroup/index.md index 7bdddb90bee35e4..69f3758daad6ccc 100644 --- a/files/en-us/web/api/gpudevice/createbindgroup/index.md +++ b/files/en-us/web/api/gpudevice/createbindgroup/index.md @@ -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`