Skip to content
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

Deterministic code generation #1376

Merged
merged 2 commits into from Jun 14, 2023

Conversation

SShikhali
Copy link
Contributor

These changes make code generation deterministic by changing std::set to std::vector when removing unused nodes

@jstone-lucasfilm
Copy link
Member

Thanks for this fix, @SShikhali, and let us know if you run into trouble with the EasyCLA process. The Linux Foundation is usually very responsive if you submit a support ticket using the links above.

@SShikhali SShikhali marked this pull request as ready for review June 13, 2023 21:55
@SShikhali
Copy link
Contributor Author

@jstone-lucasfilm should be fixed now, thanks :)

Copy link
Member

@jstone-lucasfilm jstone-lucasfilm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting this fix together, @SShikhali!

To make sure we don't lose any efficiency with respect to the original version, it may be better to maintain both a vector and a set, as in the following:

std::set<ShaderNode*> usedNodeSet;
std::vector<ShaderNode*> usedNodeVec;

This would allow us to efficiently maintain a vector of unique nodes with logic like the following:

ShaderNode* node = edge.upstream->getNode();
if (usedNodeSet.count(node) == 0)
{
    usedNodeSet.insert(node);
    usedNodeVec.push_back(node);
}

An at the end of the function, we could then simply replace the resize and assign calls with the following:

_nodeOrder = usedNodeVec;

@SShikhali
Copy link
Contributor Author

@jstone-lucasfilm yes, that's better. Pushed the improved version

Copy link
Member

@jstone-lucasfilm jstone-lucasfilm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, thanks @SShikhali!

I'm CC'ing @niklasharrysson for his thoughts before we merge, but I don't have any concerns on my side.

Copy link
Contributor

@niklasharrysson niklasharrysson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks for the fix @SShikhali

@jstone-lucasfilm jstone-lucasfilm merged commit 7c9a709 into AcademySoftwareFoundation:main Jun 14, 2023
14 checks passed
Michaelredaa pushed a commit to Michaelredaa/MaterialX that referenced this pull request Oct 21, 2023
These changes make code generation deterministic by changing std::set to std::vector when removing unused nodes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants