Nodes: avoid slow and unecessary node group updates on file read

On file read we need to update group nodes in case the group they refer to
has changed its inputs and outputs. This had O(n^2) time complexity and was
updating all datablocks even if they did not change.
This commit is contained in:
2019-04-20 20:25:22 +02:00
parent 62421470ee
commit d730e512ac
20 changed files with 119 additions and 124 deletions

View File

@@ -235,8 +235,8 @@ static bNode *ntree_shader_relink_output_from_group(bNodeTree *ntree,
}
/* Need to update tree so all node instances nodes gets proper sockets. */
node_group_verify(ntree, group_node, &group_ntree->id);
node_group_output_verify(group_ntree, group_output_node, &group_ntree->id);
node_group_update(ntree, group_node);
node_group_output_update(group_ntree, group_output_node);
ntreeUpdateTree(G.main, group_ntree);
/* Remove other shader output nodes so that only the new one can be selected as active. */
@@ -576,9 +576,9 @@ static void ntree_shader_link_builtin_group_normal(bNodeTree *ntree,
group_ntree, SOCK_IN, "NodeSocketVector", "Normal");
/* Need to update tree so all node instances nodes gets proper sockets. */
bNode *group_input_node = ntreeFindType(group_ntree, NODE_GROUP_INPUT);
node_group_verify(ntree, group_node, &group_ntree->id);
node_group_update(ntree, group_node);
if (group_input_node) {
node_group_input_verify(group_ntree, group_input_node, &group_ntree->id);
node_group_input_update(group_ntree, group_input_node);
}
ntreeUpdateTree(G.main, group_ntree);
/* Assumes sockets are always added at the end. */

View File

@@ -129,7 +129,7 @@ void register_node_type_sh_bsdf_hair_principled(void)
node_type_size_preset(&ntype, NODE_SIZE_LARGE);
node_type_init(&ntype, node_shader_init_hair_principled);
node_type_storage(&ntype, "", NULL, NULL);
node_type_update(&ntype, node_shader_update_hair_principled, NULL);
node_type_update(&ntype, node_shader_update_hair_principled);
nodeRegisterType(&ntype);
}

View File

@@ -217,7 +217,7 @@ void register_node_type_sh_bsdf_principled(void)
node_type_init(&ntype, node_shader_init_principled);
node_type_storage(&ntype, "", NULL, NULL);
node_type_gpu(&ntype, node_shader_gpu_bsdf_principled);
node_type_update(&ntype, node_shader_update_principled, NULL);
node_type_update(&ntype, node_shader_update_principled);
nodeRegisterType(&ntype);
}

View File

@@ -245,7 +245,7 @@ void register_node_type_sh_group(void)
node_type_socket_templates(&ntype, NULL, NULL);
node_type_size(&ntype, 140, 60, 400);
node_type_label(&ntype, node_group_label);
node_type_update(&ntype, NULL, node_group_verify);
node_type_group_update(&ntype, node_group_update);
node_type_exec(&ntype, group_initexec, group_freeexec, group_execute);
node_type_gpu(&ntype, gpu_group_execute);

View File

@@ -107,7 +107,7 @@ void register_node_type_sh_subsurface_scattering(void)
node_type_init(&ntype, node_shader_init_subsurface_scattering);
node_type_storage(&ntype, "", NULL, NULL);
node_type_gpu(&ntype, node_shader_gpu_subsurface_scattering);
node_type_update(&ntype, node_shader_update_subsurface_scattering, NULL);
node_type_update(&ntype, node_shader_update_subsurface_scattering);
nodeRegisterType(&ntype);
}

View File

@@ -122,7 +122,7 @@ void register_node_type_sh_tex_voronoi(void)
node_type_storage(
&ntype, "NodeTexVoronoi", node_free_standard_storage, node_copy_standard_storage);
node_type_gpu(&ntype, node_shader_gpu_tex_voronoi);
node_type_update(&ntype, node_shader_update_tex_voronoi, NULL);
node_type_update(&ntype, node_shader_update_tex_voronoi);
nodeRegisterType(&ntype);
}