Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGPUAttributeUtils: fix updateAttribute() when using range (#29966) #29967

Merged
merged 2 commits into from
Nov 26, 2024

Conversation

holtsetio
Copy link
Contributor

Related issue: #29966

Description

When using updateAttribute() with a range, the range start and count were wrongfully multiplied by array.BYTES_PER_ELEMENT before calling writeBuffer(), even though the writeBuffer() function expects the range start and count as number of typed array elements, not as bytes.

Copy link

github-actions bot commented Nov 26, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 339.14
78.99
339.14
78.99
+0 B
+0 B
WebGPU 483.41
134.17
483.51
134.22
+100 B
+51 B
WebGPU Nodes 482.88
134.07
482.98
134.13
+100 B
+54 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 464.62
111.98
464.62
111.98
+0 B
+0 B
WebGPU 552.54
149.53
552.64
149.58
+100 B
+48 B
WebGPU Nodes 508.42
139.24
508.52
139.29
+100 B
+47 B

@RenaudRohlinger
Copy link
Collaborator

Good catch! Thanks!

Related PR:
#27103

@RenaudRohlinger
Copy link
Collaborator

Some additional context:

https://www.w3.org/TR/webgpu/#dom-gpuqueue-writebuffer

If data is an ArrayBuffer or DataView, let the element type be "byte". Otherwise, data is a TypedArray; let the element type be the type of the TypedArray.

Which means that ArrayBuffer or DataView still require * array.BYTES_PER_ELEMENT.

I suggest we add a condition const isTypedArray = ArrayBuffer.isView( attribute.array ) && attribute.array instanceof DataView !== true to handle both case.

@RenaudRohlinger
Copy link
Collaborator

Updated the PR consequently.

@RenaudRohlinger RenaudRohlinger merged commit a0a25ea into mrdoob:dev Nov 26, 2024
12 checks passed
@sunag sunag added this to the r171 milestone Nov 26, 2024
@holtsetio holtsetio deleted the fix-updateAttributeWithRange branch November 26, 2024 09:50
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