Skip to content

Commit 8facdad

Browse files
Use copyBufferToBuffer overload (#500)
This PR uses copyBufferToBuffer overload following gpuweb/gpuweb#5098. Note that it should be merged only when browsers have started implementing it. FYI It is currently gated behind the WebGPUExperimentalFeatures blink runtime feature in Chromium. See https://chromium-review.googlesource.com/c/chromium/src/+/6401714
1 parent fd5fbb1 commit 8facdad

File tree

6 files changed

+8
-33
lines changed

6 files changed

+8
-33
lines changed

sample/a-buffer/main.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -567,13 +567,7 @@ const configure = () => {
567567

568568
for (let slice = 0; slice < numSlices; ++slice) {
569569
// initialize the heads buffer
570-
commandEncoder.copyBufferToBuffer(
571-
headsInitBuffer,
572-
0,
573-
headsBuffer,
574-
0,
575-
headsInitBuffer.size
576-
);
570+
commandEncoder.copyBufferToBuffer(headsInitBuffer, headsBuffer);
577571

578572
const scissorX = 0;
579573
const scissorY = slice * sliceHeight;

sample/bitonicSort/main.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -756,10 +756,7 @@ SampleInitFactoryWebGPU(
756756
);
757757
commandEncoder.copyBufferToBuffer(
758758
timestampQueryResolveBuffer,
759-
0,
760-
timestampQueryResultBuffer,
761-
0,
762-
2 * BigInt64Array.BYTES_PER_ELEMENT
759+
timestampQueryResultBuffer
763760
);
764761
}
765762
settings['Step Index'] = settings['Step Index'] + 1;
@@ -803,18 +800,11 @@ SampleInitFactoryWebGPU(
803800
// Copy GPU accessible buffers to CPU accessible buffers
804801
commandEncoder.copyBufferToBuffer(
805802
elementsOutputBuffer,
806-
0,
807-
elementsStagingBuffer,
808-
0,
809-
elementsBufferSize
803+
elementsStagingBuffer
810804
);
811-
812805
commandEncoder.copyBufferToBuffer(
813806
atomicSwapsOutputBuffer,
814-
0,
815-
atomicSwapsStagingBuffer,
816-
0,
817-
Uint32Array.BYTES_PER_ELEMENT
807+
atomicSwapsStagingBuffer
818808
);
819809
}
820810
device.queue.submit([commandEncoder.finish()]);

sample/computeBoids/main.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,7 @@ function frame() {
289289
usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ,
290290
});
291291
commandEncoder.resolveQuerySet(querySet, 0, 4, resolveBuffer, 0);
292-
commandEncoder.copyBufferToBuffer(
293-
resolveBuffer,
294-
0,
295-
resultBuffer,
296-
0,
297-
resultBuffer.size
298-
);
292+
commandEncoder.copyBufferToBuffer(resolveBuffer, resultBuffer);
299293
}
300294

301295
device.queue.submit([commandEncoder.finish()]);

sample/occlusionQuery/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ function render(now: number) {
311311
pass.end();
312312
encoder.resolveQuerySet(querySet, 0, objectInfos.length, resolveBuf, 0);
313313
if (resultBuf.mapState === 'unmapped') {
314-
encoder.copyBufferToBuffer(resolveBuf, 0, resultBuf, 0, resultBuf.size);
314+
encoder.copyBufferToBuffer(resolveBuf, resultBuf);
315315
}
316316

317317
device.queue.submit([encoder.finish()]);

sample/timestampQuery/TimestampQueryManager.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@ export default class TimestampQueryManager {
7777
// Copy values to the mappable buffer
7878
commandEncoder.copyBufferToBuffer(
7979
this.#timestampBuffer,
80-
0,
81-
this.#timestampMapBuffer,
82-
0,
83-
this.#timestampBuffer.size
80+
this.#timestampMapBuffer
8481
);
8582
}
8683
}

sample/workloadSimulator/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ <h2><center>Web graphics workload simulator</center></h2>
788788
new Float32Array(buffer.getMappedRange()).set(mapAsyncArray);
789789
buffer.unmap();
790790
const commandEncoder = device.createCommandEncoder();
791-
commandEncoder.copyBufferToBuffer(buffer, 0, mapAsyncTargetBuffer, 0, mapAsyncArray.byteLength);
791+
commandEncoder.copyBufferToBuffer(buffer, mapAsyncTargetBuffer);
792792
// TODO: combine this submit with the main one, but we'll have to delay calling mapAsync until after the submit.
793793
device.queue.submit([commandEncoder.finish()]);
794794
// TODO: use this data during rendering.

0 commit comments

Comments
 (0)