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

Proposal: InstancedMesh.updateRanges -> array of update ranges #26562

Closed
trusktr opened this issue Aug 10, 2023 · 3 comments
Closed

Proposal: InstancedMesh.updateRanges -> array of update ranges #26562

trusktr opened this issue Aug 10, 2023 · 3 comments

Comments

@trusktr
Copy link
Contributor

trusktr commented Aug 10, 2023

Description

It looks like only a single updateRange is supported, and gl.bufferSubData gets called only once for that range.

Solution

To allow higher control of optimization by Threejs users, a new .updateRanges property could be an array of update ranges, and in WebGLAttributes it call loop on those and call gl.buffSubData for each range.

Alternatives

n/a

Additional context

This may allow multiple sets of instances to be updated per frame.

For example, if someone has 1 million instances, maybe they only want to update 10 through 20, 1_000 through 1_100, and 500_000 through 500_005. For this they can define three update ranges, and avoid having to, at minimum, define a single range from 10 through 500_005. The array will allow uploading data for 115 instances instead of (at least) 499_995 instances.

@Mugen87
Copy link
Collaborator

Mugen87 commented Aug 10, 2023

It was tried to implement this once, see #13393. But it seems there was a performance issue that caused the OP to close the PR.

@trusktr
Copy link
Contributor Author

trusktr commented Aug 12, 2023

Yeah that's the idea. Yeah, creating and replacing arrays every frame is not gonna be ideal. We'd need to re-use objects if we'll be adding/removing them.

Another idea is instead of an array of objects, it could be a Map<number, number> or Record<number, number> (pairs of start,count), then iterating the key-value pairs.

With an array of objects, or with a map, an updateRangeCount would make it easy to specify how many update ranges to iterate over (default to all).

For back compat, updateRange could stay the same, and a new updateRanges (plural) could have multiple ranges.

@Mugen87
Copy link
Collaborator

Mugen87 commented Dec 10, 2023

Fixed via #27103.

@Mugen87 Mugen87 closed this as completed Dec 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants