Skip to content

[Web] Avoid copies when uploading WASM memory to WebGPU - #20165

Open
akaashrp wants to merge 1 commit into
apache:mainfrom
akaashrp:memory/02-borrowed-wasm-upload
Open

[Web] Avoid copies when uploading WASM memory to WebGPU#20165
akaashrp wants to merge 1 commit into
apache:mainfrom
akaashrp:memory/02-borrowed-wasm-upload

Conversation

@akaashrp

Copy link
Copy Markdown
Contributor

Avoid an intermediate Uint8Array copy when uploading aligned data from WASM memory to WebGPU.

  • Add a bounds-checked borrowed view of Wasm linear memory
  • Pass that view directly to GPUQueue.writeBuffer
  • Preserve padding for unaligned transfers
  • Round GPU allocations and readbacks to WebGPU’s four-byte copy alignment
  • Validate GPU copy offsets and handle zero-length readbacks

writeBuffer snapshots its source before returning, so the borrowed WASM view does not need to remain valid after the call.

queue.writeBuffer copies its source before returning, so aligned uploads can read directly from Wasm linear memory instead of first copying into another Uint8Array.

Use a checked view for aligned transfers. Keep the padded buffer for unaligned lengths, and align GPU allocations and readback copies to WebGPU copy requirements.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant