-
Notifications
You must be signed in to change notification settings - Fork 367
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
Cleanup old unused code for conditional nodes #1344
Merged
jstone-lucasfilm
merged 4 commits into
AcademySoftwareFoundation:main
from
niklasharrysson:code_cleanup
Apr 26, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0df88cf
Cleanup old unused code for handling of conditional nodes.
niklasharrysson e660d9d
Cleanup additional left-over code for handling of conditional nodes.
niklasharrysson 422c368
Merge remote-tracking branch 'aswf/main' into code_cleanup
niklasharrysson fdc543e
Added wrapper to keep but deprecate the old method
niklasharrysson 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -959,13 +959,6 @@ void ShaderGraph::finalize(GenContext& context) | |
// Sort the nodes in topological order. | ||
topologicalSort(); | ||
|
||
// Calculate scopes for all nodes in the graph. | ||
// | ||
// TODO: Enable calculateScopes() again when support for | ||
// conditional nodes are improved. | ||
// | ||
// calculateScopes(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where the feature where disabled a long time ago by not performing the scope calculations. |
||
|
||
if (context.getOptions().shaderInterfaceType == SHADER_INTERFACE_COMPLETE) | ||
{ | ||
// Publish all node inputs that has not been connected already. | ||
|
@@ -1235,75 +1228,6 @@ void ShaderGraph::topologicalSort() | |
} | ||
} | ||
|
||
void ShaderGraph::calculateScopes() | ||
{ | ||
// | ||
// Calculate scopes for all nodes, considering branching from conditional nodes | ||
// | ||
// TODO: Refactor the scope handling, using scope id's instead | ||
// | ||
|
||
if (_nodeOrder.empty()) | ||
{ | ||
return; | ||
} | ||
|
||
size_t lastNodeIndex = _nodeOrder.size() - 1; | ||
ShaderNode* lastNode = _nodeOrder[lastNodeIndex]; | ||
lastNode->getScopeInfo().type = ShaderNode::ScopeInfo::GLOBAL; | ||
|
||
std::set<ShaderNode*> nodeUsed; | ||
nodeUsed.insert(lastNode); | ||
|
||
// Iterate nodes in reversed toplogical order such that every node is visited AFTER | ||
// each of the nodes that depend on it have been processed first. | ||
for (int nodeIndex = int(lastNodeIndex); nodeIndex >= 0; --nodeIndex) | ||
{ | ||
ShaderNode* node = _nodeOrder[nodeIndex]; | ||
|
||
// Once we visit a node the scopeInfo has been determined and it will not be changed | ||
// By then we have visited all the nodes that depend on it already | ||
if (nodeUsed.count(node) == 0) | ||
{ | ||
continue; | ||
} | ||
|
||
const bool isIfElse = node->hasClassification(ShaderNode::Classification::IFELSE); | ||
const bool isSwitch = node->hasClassification(ShaderNode::Classification::SWITCH); | ||
|
||
const ShaderNode::ScopeInfo& currentScopeInfo = node->getScopeInfo(); | ||
|
||
for (size_t inputIndex = 0; inputIndex < node->numInputs(); ++inputIndex) | ||
{ | ||
ShaderInput* input = node->getInput(inputIndex); | ||
|
||
if (input->getConnection()) | ||
{ | ||
ShaderNode* upstreamNode = input->getConnection()->getNode(); | ||
|
||
// Create scope info for this network brach | ||
// If it's a conditonal branch the scope is adjusted | ||
ShaderNode::ScopeInfo newScopeInfo = currentScopeInfo; | ||
if (isIfElse && (inputIndex == 2 || inputIndex == 3)) | ||
{ | ||
newScopeInfo.adjustAtConditionalInput(node, int(inputIndex), 0x12); | ||
} | ||
else if (isSwitch && inputIndex != node->numInputs() - 1) | ||
{ | ||
const uint32_t fullMask = (1 << node->numInputs()) - 1; | ||
newScopeInfo.adjustAtConditionalInput(node, int(inputIndex), fullMask); | ||
} | ||
|
||
// Add the info to the upstream node | ||
ShaderNode::ScopeInfo& upstreamScopeInfo = upstreamNode->getScopeInfo(); | ||
upstreamScopeInfo.merge(newScopeInfo); | ||
|
||
nodeUsed.insert(upstreamNode); | ||
} | ||
} | ||
} | ||
} | ||
|
||
void ShaderGraph::setVariableNames(GenContext& context) | ||
{ | ||
// Make sure inputs and outputs have variable names valid for the | ||
|
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
Oops, something went wrong.
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.
This parameter has no effect since the feature is not in use. But note that this is a change to shader generation API.
Since there is a default value on the parameter calls to the API are not effected, and it's only derived shader generators that my be affected by this change, if they happen to override this function. I suspect that's very rare. But let me know if this API breakage needs to be handled with more care, and we should keep the parameter in for now.
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.
@niklasharrysson The approach I've been taking for backwards compatibility is to add a deprecated wrapper for the original function interface, so that existing clients can continue to build their code with the latest version of MaterialX.
Now that we've set C++14 as the baseline for MaterialX, we can additionally mark these wrappers with the
[[deprecated]]
keyword, so that clients receive a warning at compile time. Here's an example of this pattern in the current codebase:MaterialX/source/MaterialXGenShader/Util.h
Line 93 in 7fa59fa
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.
That's a great pattern to follow. I have added a wrapper now.