-
Notifications
You must be signed in to change notification settings - Fork 366
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
Refine dot node elision and remove unused code #1522
Changes from all commits
6510b97
98dcacc
5aecd59
857ab86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1027,48 +1027,16 @@ void ShaderGraph::optimize(GenContext& context) | |
} | ||
else if (node->hasClassification(ShaderNode::Classification::DOT)) | ||
{ | ||
// Dot nodes without modifiers can be elided by moving their connection downstream. | ||
// Filename dot nodes must be elided so they do not create extra samplers. | ||
ShaderInput* in = node->getInput("in"); | ||
if (in->getChannels().empty()) | ||
if (in->getChannels().empty() && in->getType() == Type::FILENAME) | ||
{ | ||
bypass(context, node, 0); | ||
++numEdits; | ||
} | ||
} | ||
else if (node->hasClassification(ShaderNode::Classification::IFELSE)) | ||
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 used to target a node called "compare" which was removed in 1.37. |
||
{ | ||
// Check if we have a constant conditional expression | ||
ShaderInput* intest = node->getInput("intest"); | ||
if (!intest->getConnection()) | ||
{ | ||
// Find which branch should be taken | ||
ShaderInput* cutoff = node->getInput("cutoff"); | ||
ValuePtr value = intest->getValue(); | ||
const float intestValue = value ? value->asA<float>() : 0.0f; | ||
const int branch = (intestValue <= cutoff->getValue()->asA<float>() ? 2 : 3); | ||
|
||
// Bypass the conditional using the taken branch | ||
bypass(context, node, branch); | ||
|
||
++numEdits; | ||
} | ||
} | ||
else if (node->hasClassification(ShaderNode::Classification::SWITCH)) | ||
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 worked in 1.37 where the "which" input was a "parameter" instead of an "input". Since this input is not marked as "uniform", it should not be elided. 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. I think this should be restored as it checks to see if indeed a uniform unconnected value. I have log an new issue and can discuss there, but now new shaders will always add more code in. (#1526) |
||
{ | ||
// Check if we have a constant conditional expression | ||
const ShaderInput* which = node->getInput("which"); | ||
if (!which->getConnection()) | ||
{ | ||
// Find which branch should be taken | ||
ValuePtr value = which->getValue(); | ||
const int branch = int(value == nullptr ? 0 : (which->getType() == Type::FLOAT ? value->asA<float>() : value->asA<int>())); | ||
|
||
// Bypass the conditional using the taken branch | ||
bypass(context, node, branch); | ||
|
||
++numEdits; | ||
} | ||
} | ||
// Adding more nodes here requires them to have an input that is tagged | ||
// "uniform" in the NodeDef or to handle very specific cases, like FILENAME. | ||
} | ||
|
||
if (numEdits > 0) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,8 +135,6 @@ const ShaderNodePtr ShaderNode::NONE = createEmptyNode(); | |
const string ShaderNode::CONSTANT = "constant"; | ||
const string ShaderNode::DOT = "dot"; | ||
const string ShaderNode::IMAGE = "image"; | ||
const string ShaderNode::COMPARE = "compare"; | ||
const string ShaderNode::SWITCH = "switch"; | ||
const string ShaderNode::SURFACESHADER = "surfaceshader"; | ||
const string ShaderNode::SCATTER_MODE = "scatter_mode"; | ||
const string ShaderNode::BSDF_R = "R"; | ||
|
@@ -292,14 +290,6 @@ ShaderNodePtr ShaderNode::create(const ShaderGraph* parent, const string& name, | |
{ | ||
newNode->_classification = Classification::TEXTURE | Classification::DOT; | ||
} | ||
else if (nodeDef.getNodeString() == COMPARE) | ||
{ | ||
newNode->_classification = Classification::TEXTURE | Classification::CONDITIONAL | Classification::IFELSE; | ||
} | ||
else if (nodeDef.getNodeString() == SWITCH) | ||
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. I'm not sure way it means to remove the texture classification here. I think nodes like try to perform filtered sample upstream will no longer work. But it could be that it does not work anyways. |
||
{ | ||
newNode->_classification = Classification::TEXTURE | Classification::CONDITIONAL | Classification::SWITCH; | ||
} | ||
// Third, check for file texture classification by group name | ||
else if (groupName == TEXTURE2D_GROUPNAME || groupName == TEXTURE3D_GROUPNAME) | ||
{ | ||
|
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.
Still solves the issue with extra samplers, but preserves the distinction between "dot" nodes and "constant" nodes.