-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Adding vectorized version of GetScenePrimPath to HdSceneDelegate #1744
Merged
pixar-oss
merged 2 commits into
PixarAnimationStudios:dev
from
sideeffects:dev_getsceneprimpaths
Mar 29, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
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.
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.
Instead of creating a list remapped a list of remapped indices it could be beneficial to have a bitset (std::vector) where each bit set marks an index to fetch. This would change the O(N) operation of
std::vector<int>::find(instanceIndex)
to an O(1) operation. There are worst case scenarios where the path for each instance is being queries which would run in O(N^2) runtime with this implementation.To avoid costly memory reallocations and copies it'd be be good to run over the list on instanceIndices twice, one time to check for the max index to determine required size of the vector and once to set all the bits for
indices[instanceIndices[i]]
.This solution has the downside of allocating too much memory for a single large index. To counter this in addition to the maximum remapped index one could determine the minimum remapped index as well to offset instanceIndex in the operator.
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, what
std::vector<int>::find(instanceIndex)
operation are you trying to avoid? I really don't understand what you're suggesting here... Could you provide some code that shows exactly what you want to 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.
I'll prepare a patch with the suggestions.
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.
@marktucker I've pushed a change with my ideas to my usd fork based on your branch here: https://github.com/mtavenrath/USD_sideeffects/commit/48b77edc80d90b0d0e014bb20e475632a913a344. There's no std::set/std::map anymore and everythings runs in linear time. I've tested the change with a scene with 1M instances querying all of them with a result of a few seconds only for all paths.
The idea is that requestedIndicesMap specifies if a index is requested at all (!= INT_MAX) and the value of requestedIndicesMap specifies the location for the index in the resulting vector. Thus there's no need to construct & iterate the result map anymore.
There is one 'worst case' scenario if someone queries the first and last instance. For this case requestedIndicesMap will be as large as the number of instances. Given it's single allocation only with sizeof(int) == 4 the cost of the allocation is neglectable when looking at memory consumed by the whole scene.
std::map/std::set quickly consume way more memory for way less elements given that each entry in those data structures has a size of at least 16 bytes and each entry is a single allocation and thus has allocation memory overhead as well.
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.
Hi @tcauchois , I'll add @mtavenrath to NVIDIA's CLA. Thanks!
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.
Thanks @mtavenrath! Just to defend my implementation a little bit, it was in fact only ever doing a
std::set<int>::find
, notstd::vector<int>::find
as you claimed. So things were never as bad as you feared. That said, your implementation is definitely going to be faster, and I suspect also smaller in memory footprint in the large-number cases that we're concerned about here. I haven't had a chance to test it out, but I definitely like the concept.For purely organization and attribution purposes, I think @tcauchois 's plan of accepting my PR, then your PR on top makes the most sense (assuming these PRs are both acceptable).
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.
@marktucker I realised that std::set::find instead of std::vetor is being used while implementing my idea and have to excuse myself for making that rash comment. Your attempt to do the picking is actually better than my first attempt which provided a function which returned a std::vectorwith all instance paths. Indexing had to be done on the applications side.
I agree that it makes sense to have two separate PRs for the two stages of optimization.