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

Update instanced buffer attributes array breaks in webGPU #29966

Closed
Samsy opened this issue Nov 25, 2024 · 2 comments
Closed

Update instanced buffer attributes array breaks in webGPU #29966

Samsy opened this issue Nov 25, 2024 · 2 comments
Milestone

Comments

@Samsy
Copy link
Contributor

Samsy commented Nov 25, 2024

Description

1 ) Create an instancedgeometry

2 ) fill it with instancedattributes

3 ) update with new values later

This works in WebGL, but not in WebGPU

This is exactly the break :

OperationError: Failed to execute 'writeBuffer' on 'GPUQueue': Number of bytes to write is too large

Screenshot 2024-11-25 at 17 22 21

My guess is, once the buffer is created, it cannot be replaced ?

Live example

Live fiddle

Uncomment the line 81

Version

last

Device

Desktop

Browser

Chrome

OS

MacOS

@holtsetio
Copy link
Contributor

holtsetio commented Nov 26, 2024

The issue is this function call in WebGPUAttributeUtils.js:

device.queue.writeBuffer(
	buffer,
	0,
	array,
	range.start * array.BYTES_PER_ELEMENT,
	range.count * array.BYTES_PER_ELEMENT
);

According to the WebGPU API, the writeBuffer command treats the last two arguments (dataOffset and size) as number of elements if the array is a TypedArray, not as number of bytes. So the multiplication by array.BYTES_PER_ELEMENT is wrong and causes the error.

As a dirty workaround until it is fixed you can just not specify an update range or divide the start and count by array.BYTES_PER_ELEMENT.

holtsetio pushed a commit to holtsetio/three.js that referenced this issue Nov 26, 2024
RenaudRohlinger added a commit that referenced this issue Nov 26, 2024
…#29967)

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

* WebGPUAttributeUtils: handle ArrayBuffer and DataView

---------

Co-authored-by: Niklas Niehus <nni@demodern.de>
Co-authored-by: Renaud Rohlinger <renaud.rohlinger@gmail.com>
@RenaudRohlinger
Copy link
Collaborator

Fixed with #29967.

Thanks!

@Mugen87 Mugen87 added this to the r171 milestone Nov 26, 2024
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

No branches or pull requests

4 participants