[js/webgpu] fix buffer size when download (#15990)

### Description
fix buffer size when download. buffer size should always be padded to
multiple of 4.

resolved issue described in #15796

>
![Image](https://user-images.githubusercontent.com/26504141/239093785-9417dffc-6f00-47b2-956d-402b43bdb0a9.png)
This commit is contained in:
Yulong Wang 2023-05-20 00:21:18 -07:00 committed by GitHub
parent 85cacf315b
commit 18f17c555d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -195,12 +195,13 @@ class GpuDataManagerImpl implements GpuDataManager {
const commandEncoder = this.backend.getCommandEncoder();
this.backend.endComputePass();
const bufferSize = calcNormalizedBufferSize(cachedData.originalSize);
const gpuReadBuffer = this.backend.device.createBuffer(
// eslint-disable-next-line no-bitwise
{size: cachedData.originalSize, usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ});
{size: bufferSize, usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ});
commandEncoder.copyBufferToBuffer(
cachedData.gpuData.buffer /* source buffer */, 0 /* source offset */, gpuReadBuffer /* destination buffer */,
0 /* destination offset */, cachedData.originalSize /* size */
0 /* destination offset */, bufferSize /* size */
);
this.backend.flush();