Skip to content

WebGPUAttributeUtils: Use correct buffer offset for updateRanges.#30617

Merged
Mugen87 merged 3 commits into
mrdoob:devfrom
zonkypop:WebGPU-updateRanges-fix
Feb 28, 2025
Merged

WebGPUAttributeUtils: Use correct buffer offset for updateRanges.#30617
Mugen87 merged 3 commits into
mrdoob:devfrom
zonkypop:WebGPU-updateRanges-fix

Conversation

@zonkypop

Copy link
Copy Markdown
Contributor

Description
Currently when using updateRanges with the WebGPU renderer, the updates are being copied to the start of the buffer.

This PR sets the correct buffer destination offset for: device.queue.writeBuffer, so updateRanges work the same as the WebGLRenderer.

@github-actions

github-actions Bot commented Feb 26, 2025

Copy link
Copy Markdown

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 336.16
78.31
336.16
78.31
+0 B
+0 B
WebGPU 522.64
145.1
522.67
145.12
+36 B
+15 B
WebGPU Nodes 522.11
145
522.14
145.01
+36 B
+16 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 465.27
112.2
465.27
112.2
+0 B
+0 B
WebGPU 593.11
160.72
593.14
160.74
+36 B
+18 B
WebGPU Nodes 548.23
150.16
548.27
150.17
+36 B
+17 B

@Mugen87

Mugen87 commented Feb 26, 2025

Copy link
Copy Markdown
Collaborator

Do you mind demonstrating the current issue with a fiddle so it is easier for us to reproduce the bug and validate your fix?

Use https://jsfiddle.net/xno7bmw0/ as a start template.

@zonkypop

Copy link
Copy Markdown
Contributor Author

Do you mind demonstrating the current issue with a fiddle so it is easier for us to reproduce the bug and validate your fix?

Here's a fiddle: https://jsfiddle.net/zonkypop/0s6u4dac/11/

You can see the difference by changing: forceWebGL: true

Tested on macOS and Linux WebGPU

Comment thread src/renderers/webgpu/utils/WebGPUAttributeUtils.js Outdated
@zonkypop zonkypop force-pushed the WebGPU-updateRanges-fix branch from 1310834 to 2850320 Compare February 27, 2025 22:05
@Mugen87 Mugen87 added this to the r175 milestone Feb 28, 2025
@Mugen87 Mugen87 changed the title WebGPUAttributeUtils: use correct buffer offset for updateRanges WebGPUAttributeUtils: Use correct buffer offset for updateRanges. Feb 28, 2025
@Mugen87 Mugen87 merged commit eaf72e6 into mrdoob:dev Feb 28, 2025
zonkypop added a commit to zonkypop/three.js that referenced this pull request Feb 28, 2025
…rdoob#30617)

* WebGPU: use correct destination offset for updateRanges

* Take into account BYTES_PER_ELEMENT for updateRanges

* Update WebGPUAttributeUtils.js

---------

Co-authored-by: Michael Herzog <michael.herzog@human-interactive.org>
@Spiri0

Spiri0 commented May 1, 2025

Copy link
Copy Markdown
Contributor

This is exactly what I was looking for to update individual parts of a storage buffer on the CPU side. I've solved this problem with a workaround so far. UpdateRanges is better.

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.

3 participants