Skip to content

Commit

Permalink
[js/webgpu] fix buffer size when download (microsoft#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 microsoft#15796

>
![Image](https://user-images.githubusercontent.com/26504141/239093785-9417dffc-6f00-47b2-956d-402b43bdb0a9.png)
  • Loading branch information
fs-eire authored May 20, 2023
1 parent b16c7a1 commit 93b04a5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions web/lib/wasm/jsep/webgpu/gpu-data-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 93b04a5

Please sign in to comment.