Skip to content

Commit

Permalink
Fix buffer length typo (mdn#36946)
Browse files Browse the repository at this point in the history
  • Loading branch information
robz authored Nov 26, 2024
1 parent d03a0af commit 7622e7e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions files/en-us/web/api/webgpu_api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ The app follows a similar structure to the basic rendering demo. We create a {{d

```js
// Define global buffer size
const BUFFER_SIZE = 1000;
const NUM_ELEMENTS = 1000;
const BUFFER_SIZE = NUM_ELEMENTS * 4; // Buffer size, in bytes

const shader = `
@group(0) @binding(0)
Expand All @@ -336,7 +337,7 @@ fn main(
local_id : vec3u,
) {
// Avoid accessing the buffer out of bounds
if (global_id.x >= ${BUFFER_SIZE}) {
if (global_id.x >= ${NUM_ELEMENTS}) {
return;
}
Expand Down Expand Up @@ -431,7 +432,7 @@ We then signal the end of the render pass command list using {{domxref("GPURende
```js
passEncoder.setPipeline(computePipeline);
passEncoder.setBindGroup(0, bindGroup);
passEncoder.dispatchWorkgroups(Math.ceil(BUFFER_SIZE / 64));
passEncoder.dispatchWorkgroups(Math.ceil(NUM_ELEMENTS / 64));

passEncoder.end();
```
Expand All @@ -447,7 +448,7 @@ commandEncoder.copyBufferToBuffer(
0, // Source offset
stagingBuffer,
0, // Destination offset
BUFFER_SIZE,
BUFFER_SIZE, // Length, in bytes
);

// End frame by passing array of command buffers to command queue for execution
Expand All @@ -461,7 +462,7 @@ Once the output data is available in the `stagingBuffer`, we use the {{domxref("
await stagingBuffer.mapAsync(
GPUMapMode.READ,
0, // Offset
BUFFER_SIZE, // Length
BUFFER_SIZE, // Length, in bytes
);

const copyArrayBuffer = stagingBuffer.getMappedRange(0, BUFFER_SIZE);
Expand Down

0 comments on commit 7622e7e

Please sign in to comment.