Depsgraph: For big graphs update pending parents in threads

Gives additional speedup from ~88 to ~91 fps with a test rig.
This commit is contained in:
Sergey Sharybin 2016-05-10 13:02:54 +02:00
parent 288bbee5b1
commit 898d040b0c
1 changed files with 37 additions and 26 deletions

View File

@ -240,43 +240,54 @@ static void deg_task_run_func(TaskPool *pool,
}
}
static void calculate_pending_parents(Depsgraph *graph, int layers)
typedef struct CalculatePengindData {
Depsgraph *graph;
int layers;
} CalculatePengindData;
static void calculate_pending_func(void *data_v, int i)
{
for (Depsgraph::OperationNodes::const_iterator it_op = graph->operations.begin();
it_op != graph->operations.end();
++it_op)
CalculatePengindData *data = (CalculatePengindData *)data_v;
Depsgraph *graph = data->graph;
int layers = data->layers;
OperationDepsNode *node = graph->operations[i];
IDDepsNode *id_node = node->owner->owner;
node->num_links_pending = 0;
node->scheduled = false;
/* count number of inputs that need updates */
if ((id_node->layers & layers) != 0 &&
(node->flag & DEPSOP_FLAG_NEEDS_UPDATE) != 0)
{
OperationDepsNode *node = *it_op;
IDDepsNode *id_node = node->owner->owner;
node->num_links_pending = 0;
node->scheduled = false;
/* count number of inputs that need updates */
if ((id_node->layers & layers) != 0 &&
(node->flag & DEPSOP_FLAG_NEEDS_UPDATE) != 0)
DEPSNODE_RELATIONS_ITER_BEGIN(node->inlinks, rel)
{
for (OperationDepsNode::Relations::const_iterator it_rel = node->inlinks.begin();
it_rel != node->inlinks.end();
++it_rel)
if (rel->from->type == DEPSNODE_TYPE_OPERATION &&
(rel->flag & DEPSREL_FLAG_CYCLIC) == 0)
{
DepsRelation *rel = *it_rel;
if (rel->from->type == DEPSNODE_TYPE_OPERATION &&
(rel->flag & DEPSREL_FLAG_CYCLIC) == 0)
OperationDepsNode *from = (OperationDepsNode *)rel->from;
IDDepsNode *id_from_node = from->owner->owner;
if ((id_from_node->layers & layers) != 0 &&
(from->flag & DEPSOP_FLAG_NEEDS_UPDATE) != 0)
{
OperationDepsNode *from = (OperationDepsNode *)rel->from;
IDDepsNode *id_from_node = from->owner->owner;
if ((id_from_node->layers & layers) != 0 &&
(from->flag & DEPSOP_FLAG_NEEDS_UPDATE) != 0)
{
++node->num_links_pending;
}
++node->num_links_pending;
}
}
}
DEPSNODE_RELATIONS_ITER_END;
}
}
static void calculate_pending_parents(Depsgraph *graph, int layers)
{
const int num_operations = graph->operations.size();
const bool do_threads = num_operations > 256;
CalculatePengindData data;
data.graph = graph;
data.layers = layers;
BLI_task_parallel_range(0, num_operations, &data, calculate_pending_func, do_threads);
}
#ifdef USE_EVAL_PRIORITY
static void calculate_eval_priority(OperationDepsNode *node)
{