GPU instances nodes removal fixes#2577
Open
2frac wants to merge 2 commits into
Open
Conversation
Contributor
Author
|
CI fail looks like a consequence of that blender 5.0 change Specifically, that part fails: glTF-Blender-IO/addons/io_scene_gltf2/__init__.py Lines 154 to 156 in d97e932 I might create separate pull request for that a bit later. |
Collaborator
|
Can you please rebase with main branch? |
Contributor
Author
|
(i meant to rebase instead of merge main, but result should be the same) |
|
This PR solves the issue. I just tested it with the official version, I was exporting an animation that also had GPU instances ON, and the animation was getting destroyed. Replaced the |
Collaborator
|
Thanks for the PR, I will have a look soon! |
2frac
force-pushed
the
gpu_instancing_deletion_fix
branch
from
December 25, 2025 12:49
2fd0544 to
a47d0c6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
It reworks code dealing with nodes instancing - in particular part which removes nodes added to instancing.
What it does
Gathers removed nodes from all scenes and applies deletion at once.
(in old code self.nodes_idx_to_remove is cleaned up in loop(not before it), which will cause to only delete nodes from last processed scene)
Uses sets to check if node is deleted, instead of lists.
This probably has the most effect on speed for big-sized instance collections(should help with glTF Exporter Hangs with Large-Scale Instancing #2199 )
Instead of calculating shifts for node indices it uses single dict mapping.
I haven't checked exact performance effect, but to iterate all deleted objects for every remaining object can result in bad speed for specific scenes. There is still some O(n^2)-ish speed behavior, but i suspect it rather related to node creation and better be investigated separately.
Also results in simpler code.
Applies new node index to animation's target.
Previously it was just checking if node is deleted, without changing index to new.
Should solve Exporting the GPU instance together with other simple TRS animations will cause the animation to play incorrectly. #2423
Examples to reproduce
All made in blender 4.4.3. For every example, both GPU instances and GN instancing should be enabled.
amount of instances can be controlled by density
for 40k instances it takes 25 seconds(before fix) vs 10 second(after)for me.
for 100k - 155 vs 48.
When exported, result is looking strange for "Scene", which likely to be caused by bad indices.
Also some "GN Instance" objects can be seen in node list in JSON, even if GN instancing is enabled as option and it should remove it.
When exported, animation target has node ids in JSON, which is too big to be real.
Note
There is more optimizations i would like to try(beside said creation), but better be done as separate pull request[s].
Instancing generally looks like it be better done using direct transform gathering from GN/instancing/particles rather than generating and unifying nodes - but that will require entirely different approach with its own problems.