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

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(); CalculatePengindData *data = (CalculatePengindData *)data_v;
it_op != graph->operations.end(); Depsgraph *graph = data->graph;
++it_op) 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; DEPSNODE_RELATIONS_ITER_BEGIN(node->inlinks, rel)
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)
{ {
for (OperationDepsNode::Relations::const_iterator it_rel = node->inlinks.begin(); if (rel->from->type == DEPSNODE_TYPE_OPERATION &&
it_rel != node->inlinks.end(); (rel->flag & DEPSREL_FLAG_CYCLIC) == 0)
++it_rel)
{ {
DepsRelation *rel = *it_rel; OperationDepsNode *from = (OperationDepsNode *)rel->from;
if (rel->from->type == DEPSNODE_TYPE_OPERATION && IDDepsNode *id_from_node = from->owner->owner;
(rel->flag & DEPSREL_FLAG_CYCLIC) == 0) if ((id_from_node->layers & layers) != 0 &&
(from->flag & DEPSOP_FLAG_NEEDS_UPDATE) != 0)
{ {
OperationDepsNode *from = (OperationDepsNode *)rel->from; ++node->num_links_pending;
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;
}
} }
} }
} }
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 #ifdef USE_EVAL_PRIORITY
static void calculate_eval_priority(OperationDepsNode *node) static void calculate_eval_priority(OperationDepsNode *node)
{ {