Fix T46782: Updating Shaders very slow with complex nodegraph

The issue was caused by not really optimal graph traversal for gathering nodes
dependencies which could have exponential complexity with a long tree branches
connected with multiple connections between them.

Now we optimize the depth traversal and perform early output if the node was
already traversed.

Please note that this adds some limitations to the use of SVM compiler's
find_dependencies() in the cases when skip_node is not NULL and one wants to
perform dependencies find sequentially with the same set. This doesn't happen
in the code, but one should be aware of this.
This commit is contained in:
Sergey Sharybin 2015-11-25 13:46:51 +05:00
parent 443b159f02
commit 8294452b14
3 changed files with 7 additions and 3 deletions

@ -306,7 +306,7 @@ void ShaderGraph::find_dependencies(ShaderNodeSet& dependencies, ShaderInput *in
/* find all nodes that this input depends on directly and indirectly */
ShaderNode *node = (input->link)? input->link->parent: NULL;
if(node) {
if(node != NULL && dependencies.find(node) == dependencies.end()) {
foreach(ShaderInput *in, node->inputs)
find_dependencies(dependencies, in);

@ -702,7 +702,7 @@ void OSLCompiler::find_dependencies(ShaderNodeSet& dependencies, ShaderInput *in
{
ShaderNode *node = (input->link)? input->link->parent: NULL;
if(node) {
if(node != NULL && dependencies.find(node) == dependencies.end()) {
foreach(ShaderInput *in, node->inputs)
if(!node_skip_input(node, in))
find_dependencies(dependencies, in);

@ -373,7 +373,11 @@ void SVMCompiler::find_dependencies(ShaderNodeSet& dependencies,
{
ShaderNode *node = (input->link)? input->link->parent: NULL;
if(node && done.find(node) == done.end() && node != skip_node) {
if(node != NULL &&
done.find(node) == done.end() &&
node != skip_node &&
dependencies.find(node) == dependencies.end())
{
foreach(ShaderInput *in, node->inputs)
if(!node_skip_input(node, in))
find_dependencies(dependencies, done, in, skip_node);