demo · v137
Per-frame Copies
The reason the spec authors added the terse overload: tight engine loops that issue dozens to hundreds of full-buffer copies per frame. Each five-argument call goes through additional bounds validation that the two-argument overload can skip. The benchmark below records both shapes back-to-back.
probing…
old: copyBufferToBuffer(src, 0, dst, 0, size)
total time
—
per-call avg
—
new: copyBufferToBuffer(src, dst)
total time
—
per-call avg
—
delta
—
the code
// Tight loop, common in compute simulations / particle systems:
function frame() {
const enc = device.createCommandEncoder();
for (let i = 0; i < copies; i++) {
enc.copyBufferToBuffer(src[i], dst[i]); // new shape
// enc.copyBufferToBuffer(src[i], 0, dst[i], 0, byteLen); // old shape
}
device.queue.submit([enc.finish()]);
}
// At >60 calls/frame the savings on validation add up.
see also
- WebGPU: copyBufferToBuffer overload — feature index
- copy-overload demo
- Spec
- ChromeStatus entry