-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
add ability to incrementally add/remove nodes from bvh #99
add ability to incrementally add/remove nodes from bvh #99
Conversation
|
Just gonna jot down my general arguments for this method over the current optimize. The ability to dynamically add/remove individual nodes is a pretty major feature that you don't get from the other rust bvh (Parry's QBvh). This approach also eliminates the need to store the depth of each node so the nodes are smaller in memory (not massively smaller but it's still something). Keeping depth actually dramatically slows this approach down because it needs to update the depths during each operation. All of this assumes that this approach also gets better/similar performance to the current one. Once I add the parallel rebuild, optimize/add/remove should be most relevant for changes of less than ~10% of the Bvh due to lack of parallelism. There are still some optimizations left on the table. Right now add/remove doesn't leave the bvh in a contiguous state in memory. I want to test adding a relayout operation that puts all the nodes back in order. There's probably more operations |
These are some incredible numbers! I might not get to review this but I hope @marstaik could take a look. Please write a CHANGELOG entry for this change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really amazing job, I tried to be as thorough as I could.
A couple of notes
- The remove function leaves dead nodes in the vector, it would be better to
Tombstone
them (we can introduce a new enum value in BvhNode. This could be handled by an actual optimize pass in the future (more on that later). - (This isn't just related to your PR) optimize has a bad name IMO. We are not performing any optimization to the BVH, only removing shapes that have changed and re-adding them.
Reviewing your changes has given me some ideas for future performance increases (things you do not have to do in this PR):
- An actual optimization step, that removes
TombStone
'd Nodes and potentially re-balances the tree, and perhaps resort the hierarchy to a depth-first traversal. I believe DFS oriented setup could potentially make traversals faster. - Making mutability of shapes occur via a handle of some kind, which when all changes to shapes are made can automatically optimize the tree when it is dropped.
self.nodes[parent_index].child_l() | ||
}; | ||
|
||
// TODO: fix potential issue leaving empty spot in self.nodes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can make the Node enum have a Gravestone
state, and then we can simply compress the node vector in the optimize function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bump
@dbenson24 lil ping :) |
@dbenson24 are you interested in continuing this? |
Hey yes sorry, recently had a baby and haven't had the time. I do want to get this cleaned up soon |
Oh shit, congratz! Take all the time you need. :) |
Ok I think I've addressed everything except for the Tombstoning. It's definitely a nice to have, but I think in practicality it would rarely be used. Because of how efficiently we can traverse the bvh in parallel to do a build, analysis that goes over the whole tree to do something like reordering it would also have to be made similarly parallel. I just realized I hadn't ported the parallel stuff over to this yet so that'll be the next PR. |
Could you also write a CHANGELOG entry for changes that people should be aware of? |
Can we do the changelog with my next PR and hold off on release until after that? I'll have it up shortly after this one is submitted. That will be the PR that builds the bvh in parallel |
Oh ok, great. |
@marstaik feel like taking another look at this one? It looks to me like all your last comments were addressed. |
@svenstaro Ill take a look soon, I was on a very long vacation :) I am back now. |
@marstaik Friendly ping :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, my life has also recently been hectic (out of country, new job in the last 6mo, etc) but should be a bit more stable for me to work on code now.
There are still some small code quality/renaming/ commented out functions that should be removed as they might cause confusion.
If you don't want to deal with the TODO related to empty nodes/tombstone-ing, maybe I can do it in a separate PR.
src/bvh/optimization.rs
Outdated
child_r_index: r_index, | ||
parent_index, | ||
}; | ||
//self.fix_depth(l_index, depth + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commented code still here
self.nodes[parent_index].child_l() | ||
}; | ||
|
||
// TODO: fix potential issue leaving empty spot in self.nodes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bump
@marstaik Happy to have you back! Should we maybe just merge this and you apply your changes on top? It might be the more efficient approach. |
No need, I think that is pretty much everything except for the tombstoning. I definitely don't want to do that in this PR. I want to get to the multithreading PR |
@dbenson24 Great to see you're still around as well! :) Would be great if we could get this PR in soon. |
I'm pretty sure this is ready to merge |
Some more clippy stuff to fix :) |
Lol these aren't even my clippy errors, clippy has added new lints that affect existing code. I have been missing them because I haven't been updating my rust nightly every time |
Weird, did we just spot a flaky test? |
@marstaik What do you think? |
@marstaik friendly ping :) |
If I hear nothing for a week, I'll just merge this. |
Finally merging this, thanks for you work @dbenson24! |
I will get the parallelization PR up soon
…On Sat, Feb 17, 2024, 4:56 AM Sven-Hendrik Haase ***@***.***> wrote:
Finally merging this, thanks for you work @dbenson24
<https://github.com/dbenson24>!
—
Reply to this email directly, view it on GitHub
<#99 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACFEVAZGHGAINP2YZDIEWGLYUB5GBAVCNFSM6AAAAAAXYCHKZSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNBZHEZDANJYGE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
leaving an initial draft of this PR here. It looks like there might be a perf regression with when I originally wrote this so I'm going to take a look at that. (post optimizaiton intersection of the 120k benchmark is massively improved, intersection with sponza isn't doing as well)