Skip to content

Commit

Permalink
[js/webgpu] fix buffer size when download (#15990)
Browse files Browse the repository at this point in the history
### 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)
fs-eire authored May 20, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 85cacf3 commit 18f17c5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions js/web/lib/wasm/jsep/webgpu/gpu-data-manager.ts
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit 18f17c5

Please sign in to comment.