-
-
Notifications
You must be signed in to change notification settings - Fork 35.7k
Texture: Add updateRanges. #30998
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
base: dev
Are you sure you want to change the base?
Texture: Add updateRanges. #30998
Conversation
I am sure the indirection texture in |
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
Great work, just a couple of thoughts: I am afraid that calling In my case, I would like to freely manage the selection of update ranges. The best choice would be to have the user call
So being updated sequentially, we can calculate the two update ranges:
To avoid trouble with the garbage collector we might also consider reusing the same objects like It would also be nice to test on Firefox these changes, I had several problems when the update calls were many. |
In the issue I opened I had suggested this signature:
but you implemented the same as
I prefer your approach because it makes things easier, but a user might also need to update a region. In that case it would be sufficent to create a separate method that creates multiple update ranges based on the number of rows, although it's probably not the best solution because it would make more update calls than necessary, but I think it's fine. What do you think about using this syntax? texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels, srcOffset);
// example how to update full consecutive rows
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, row, width, count, glFormat, glType, data, row * width * channels); adding the offest as the last parameter, avoiding the overhead due to _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, x );
_gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, y ); However, I would have to test this and see if these methods are equivalent |
This needs an experiment to inform and is why this PR is in draft status so we do not risk regression. It's possible we restrict to only a few ranges at most (or a decent heuristic) and greedily merge within
The current implementation assumes that update ranges refer to contiguous rows of memory, but it can be modified to split non-contiguous rows of memory into separate calls (before the optimization pass). This should be an implementation detail. If overloads are okay, I would want to break this into another PR and mirror the API with |
I am removing changes to It would help to have a minimal example showcasing a partial update to |
Related issue: #30184
Description
Adds an update ranges API to textures, mirroring
BufferAttribute
. Note that the current implementation assumes update ranges refer to contiguous blocks or rows of memory; non-contiguous updates should be split into multiple update ranges. Adjacent update ranges are merged similarly to #29189 with additional checks according to the texture image layout.A good application of partial updates to textures would be
BatchedMesh
, where updating a single object's matrix or visibility flushes the entire texture, which is very slow and can cause a memory management event (crash!). It should serve as a good testbed for usability/performance with the webgl_mesh_batch example.