-
Notifications
You must be signed in to change notification settings - Fork 945
bvh_node: no more const qualifier of objects array, axis sorting "in place" #1409
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
Conversation
…ments -so now we are essentially changing the objects vector in place via sorting -this should be ok though because we don't need the scene objects array any longer after the bvh has been built -removed 2nd unnecessary branch within condition "object_span == 2" -did not change bbox calculation in the beginning of constructor as using "for const & auto : objects ..." made everything a lot slower
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.
We cannot mutate the input list. Any outstanding references into the original hittable list array would be invalidated.
books/RayTracingTheNextWeek.html
Outdated
left = objects[start]; | ||
right = objects[start+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.
Indent error.
You can pretty much achieve all this by going with my original suggestion: the |
Agreed. The cost of the initial copy should be negligible and you should still see a similar performance improvement by removing the intermediate per-node allocations and copies. |
OK thank you for the feedback! Will take another stab at it. |
Thank you for bearing with the back and forth and the detailed performance data you have posted. I'm eager to see the new measurements. |
Hi! After looking at these changes a bit closer, I am running into a few issues... Currently, everything in the bvh is based on the type
The whole beauty and simplicity of the bvh currently is based on the fact that we only need to deal with one data type and therefore can treat all these items the same at all levels. We probably agree that we don't want to introduce heterogeneous data types, so if our input is now an array of raw
Otherwise we cannot store hittables and bvh nodes in the same Creation of new bvh nodes used to be: and it becomes: We have to switch to Issues:
For these reasons, I am afraid I won't be able to do these code changes unless you have tips on how to solve this elegantly. An easy solution to the problem about the mutated input list (without converting the bvh to raw pointers) would be to remove the const reference and copy input list by value: That's an easy fix that I could provide if you want me to. |
https://www.youtube.com/watch?v=7FPELc1wEvk Gotcha. I agree with your conclusion. Might have been nice to simplify things, but let's keep everything as |
…nput hittable_list -updated listings in book 2 -fixed indentation error in RayTracingTheNextWeek.html
Ok, thank you for the feedback and the hilarious video! 🤣 I updated pull request with: speed wise, the time for copying the input once seems negligible:
|
Holy cow; that took me longer to grok than it should have! I couldn't figure out why this wasn't just a reversion of everything. Finally realized that the constructor without indices creates an implicit copy of the source list, and the constructor with the indices just uses the reference to the copy. It makes me want to explain this subtlety somehow, mostly because it's due to subtle aspects of C++ that would be easy to mistakenly drop when implementing in other languages. I think I'll just squash+merge this in, and then issue a follow-up PR to explain this subtlety. |
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.
I'll add some more clarification in a subsequent change.
(Also, please keep the first lines of commits to 50 characters, and the remainder of commit comments to 72 characters.) |
based on @armansito's and @hollasch's suggestions in #1391 (see also further explanation and tests in #1388 )
-removed const qualifier for
objects
vector inbvh_node
constructor so sorting is done "in place"-hopefully ok because we don't need the scene objects array after being consumed by the bvh
-removed 2nd unnecessary branch within condition "object_span == 2"
-did not change for loop of bbox calculation because using
for (auto& obj : objects)
instead offor (size_t object_index=0; object_index < size; object_index++)
made everything a lot slower-updated bvh source code in book2 and book3
-modified listings in book2
-added note to changelog
-added names to acknowledgements (Arman was already there 😄)