[Bf-blender-cvs] [d7bf56c] depsgraph_cleanup: Depsgraph: Move evaluation files into own folder

Sergey Sharybin noreply at git.blender.org
Thu May 26 10:02:31 CEST 2016


Commit: d7bf56c1237cc462f6d70f103eba657adc17df24
Author: Sergey Sharybin
Date:   Wed May 25 16:35:55 2016 +0200
Branches: depsgraph_cleanup
https://developer.blender.org/rBd7bf56c1237cc462f6d70f103eba657adc17df24

Depsgraph: Move evaluation files into own folder

===================================================================

M	source/blender/depsgraph/CMakeLists.txt
M	source/blender/depsgraph/intern/depsgraph_eval.cc
A	source/blender/depsgraph/intern/eval/deg_eval.cc
A	source/blender/depsgraph/intern/eval/deg_eval.h

===================================================================

diff --git a/source/blender/depsgraph/CMakeLists.txt b/source/blender/depsgraph/CMakeLists.txt
index bda5f5a..921466b 100644
--- a/source/blender/depsgraph/CMakeLists.txt
+++ b/source/blender/depsgraph/CMakeLists.txt
@@ -45,6 +45,7 @@ set(SRC
 	intern/builder/deg_builder.cc
 	intern/builder/deg_builder_nodes.cc
 	intern/builder/deg_builder_relations.cc
+	intern/eval/deg_eval.cc
 	intern/depsgraph.cc
 	intern/depsnode.cc
 	intern/depsnode_component.cc
@@ -65,9 +66,11 @@ set(SRC
 	DEG_depsgraph_build.h
 	DEG_depsgraph_debug.h
 	DEG_depsgraph_query.h
+
 	intern/builder/deg_builder.h
 	intern/builder/deg_builder_nodes.h
 	intern/builder/deg_builder_relations.h
+	intern/eval/deg_eval.h
 	intern/depsgraph.h
 	intern/depsnode.h
 	intern/depsnode_component.h
diff --git a/source/blender/depsgraph/intern/depsgraph_eval.cc b/source/blender/depsgraph/intern/depsgraph_eval.cc
index 5d56487..ec884b6 100644
--- a/source/blender/depsgraph/intern/depsgraph_eval.cc
+++ b/source/blender/depsgraph/intern/depsgraph_eval.cc
@@ -32,11 +32,8 @@
 
 #include "MEM_guardedalloc.h"
 
-#include "PIL_time.h"
-
 extern "C" {
 #include "BLI_utildefines.h"
-#include "BLI_task.h"
 
 #include "BKE_depsgraph.h"
 #include "BKE_scene.h"
@@ -44,14 +41,9 @@ extern "C" {
 #include "DEG_depsgraph.h"
 } /* extern "C" */
 
-#include "atomic_ops.h"
-
+#include "eval/deg_eval.h"
 #include "depsgraph.h"
-#include "depsnode.h"
-#include "depsnode_component.h"
 #include "depsnode_operation.h"
-#include "depsgraph_debug.h"
-#include "depsgraph_util_foreach.h"
 
 #ifdef WITH_LEGACY_DEPSGRAPH
 static bool use_legacy_depsgraph = true;
@@ -119,329 +111,6 @@ void DEG_evaluation_context_free(EvaluationContext *eval_ctx)
 	MEM_freeN(eval_ctx);
 }
 
-/* ********************** */
-/* Evaluation Entrypoints */
-
-/* Forward declarations. */
-static void schedule_children(TaskPool *pool,
-                              Depsgraph *graph,
-                              OperationDepsNode *node,
-                              const int layers,
-                              const int thread_id);
-
-struct DepsgraphEvalState {
-	EvaluationContext *eval_ctx;
-	Depsgraph *graph;
-	int layers;
-};
-
-static void deg_task_run_func(TaskPool *pool,
-                              void *taskdata,
-                              int thread_id)
-{
-	DepsgraphEvalState *state = (DepsgraphEvalState *)BLI_task_pool_userdata(pool);
-	OperationDepsNode *node = (OperationDepsNode *)taskdata;
-
-	BLI_assert(!node->is_noop() && "NOOP nodes should not actually be scheduled");
-
-	/* Should only be the case for NOOPs, which never get to this point. */
-	BLI_assert(node->evaluate);
-
-	while (true) {
-		/* Get context. */
-		// TODO: who initialises this? "Init" operations aren't able to initialise it!!!
-		/* TODO(sergey): We don't use component contexts at this moment. */
-		/* ComponentDepsNode *comp = node->owner; */
-		BLI_assert(node->owner != NULL);
-
-		/* Since we're not leaving the thread for until the graph branches it is
-		 * possible to have NO-OP on the way. for which evaluate() will be NULL.
-		 * but that's all fine, we'll just scheduler it's children.
-		 */
-		if (node->evaluate) {
-			/* Take note of current time. */
-			double start_time = PIL_check_seconds_timer();
-			DepsgraphDebug::task_started(state->graph, node);
-
-			/* Perform operation. */
-			node->evaluate(state->eval_ctx);
-
-			/* Note how long this took. */
-			double end_time = PIL_check_seconds_timer();
-			DepsgraphDebug::task_completed(state->graph,
-			                               node,
-			                               end_time - start_time);
-		}
-
-		/* If there's only one outgoing link we try to immediately switch to
-		 * that node evaluation, without leaving the thread.
-		 *
-		 * It's only doable if the child don't have extra relations or all they
-		 * are satisfied.
-		 *
-		 * TODO(sergey): Checks here can be de-duplicated with the ones from
-		 * schedule_node(), however, how to do it nicely?
-		 */
-		if (node->outlinks.size() == 1) {
-			DepsRelation *rel = node->outlinks[0];
-			OperationDepsNode *child = (OperationDepsNode *)rel->to;
-			BLI_assert(child->type == DEPSNODE_TYPE_OPERATION);
-			if (!child->scheduled) {
-				int id_layers = child->owner->owner->layers;
-				if (!((child->flag & DEPSOP_FLAG_NEEDS_UPDATE) != 0 &&
-				      (id_layers & state->layers) != 0))
-				{
-					/* Node does not need an update, so can;t continue with the
-					 * chain and need to switch to another one by leaving the
-					 * thread.
-					 */
-					break;
-				}
-				if ((rel->flag & DEPSREL_FLAG_CYCLIC) == 0) {
-					BLI_assert(child->num_links_pending > 0);
-					atomic_sub_uint32(&child->num_links_pending, 1);
-				}
-				if (child->num_links_pending == 0) {
-					bool is_scheduled = atomic_fetch_and_or_uint8((uint8_t *)&child->scheduled, (uint8_t)true);
-					if (!is_scheduled) {
-						/* Node was not scheduled, switch to it! */
-						node = child;
-					}
-					else {
-						/* Someone else scheduled the node, leaving us
-						 * unemployed in this thread, we're leaving.
-						 */
-						break;
-					}
-				}
-				else {
-					/* There are other dependencies on the child, can't do
-					 * anything in the current thread.
-					 */
-					break;
-				}
-			}
-			else {
-				/* Happens when having cyclic dependencies.
-				 *
-				 * Nothing to do here, single child was already scheduled, we
-				 * can leave the thread now.
-				 */
-				break;
-			}
-		}
-		else {
-			/* TODO(sergey): It's possible to use one of the outgoing relations
-			 * as a chain which we'll try to keep alive, but it's a bit more
-			 * involved change.
-			 */
-			schedule_children(pool, state->graph, node, state->layers, thread_id);
-			break;
-		}
-	}
-}
-
-typedef struct CalculatePengindData {
-	Depsgraph *graph;
-	int layers;
-} CalculatePengindData;
-
-static void calculate_pending_func(void *data_v, int i)
-{
-	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)
-	{
-		foreach (DepsRelation *rel, node->inlinks) {
-			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)
-				{
-					++node->num_links_pending;
-				}
-			}
-		}
-	}
-}
-
-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)
-{
-	if (node->done) {
-		return;
-	}
-	node->done = 1;
-
-	if (node->flag & DEPSOP_FLAG_NEEDS_UPDATE) {
-		/* XXX standard cost of a node, could be estimated somewhat later on */
-		const float cost = 1.0f;
-		/* NOOP nodes have no cost */
-		node->eval_priority = node->is_noop() ? cost : 0.0f;
-
-		foreach (DepsRelation *rel, node->outlinks) {
-			OperationDepsNode *to = (OperationDepsNode *)rel->to;
-			BLI_assert(to->type == DEPSNODE_TYPE_OPERATION);
-			calculate_eval_priority(to);
-			node->eval_priority += to->eval_priority;
-		}
-	}
-	else {
-		node->eval_priority = 0.0f;
-	}
-}
-#endif
-
-/* Schedule a node if it needs evaluation.
- *   dec_parents: Decrement pending parents count, true when child nodes are scheduled
- *                after a task has been completed.
- */
-static void schedule_node(TaskPool *pool, Depsgraph *graph, int layers,
-                          OperationDepsNode *node, bool dec_parents,
-                          const int thread_id)
-{
-	int id_layers = node->owner->owner->layers;
-	
-	if ((node->flag & DEPSOP_FLAG_NEEDS_UPDATE) != 0 &&
-	    (id_layers & layers) != 0)
-	{
-		if (dec_parents) {
-			BLI_assert(node->num_links_pending > 0);
-			atomic_sub_uint32(&node->num_links_pending, 1);
-		}
-
-		if (node->num_links_pending == 0) {
-			bool is_scheduled = atomic_fetch_and_or_uint8((uint8_t *)&node->scheduled, (uint8_t)true);
-			if (!is_scheduled) {
-				if (node->is_noop()) {
-					/* skip NOOP node, schedule children right away */
-					schedule_children(pool, graph, node, layers, thread_id);
-				}
-				else {
-					/* children are scheduled once this task is completed */
-					BLI_task_pool_push_from_thread(pool,
-					                               deg_task_run_func,
-					                               node,
-					                               false,
-					                               TASK_PRIORITY_LOW,
-					                               thread_id);
-				}
-			}
-		}
-	}
-}
-
-static void schedule_graph(TaskPool *pool,
-                           Depsgraph *graph,
-                           const int layers)
-{
-	foreach (OperationDepsNode *node, graph->operations) {
-		schedule_node(pool, graph, layers, node, false, 0);
-	}
-}
-
-static void schedule_children(TaskPool *pool,
-                              Depsgraph *graph,
-                              OperationDepsNode *node,
-                              const int layers,
-                              const int thread_id)
-{
-	foreach (DepsRelation *rel, node->outlinks) {
-		OperationDepsNode *child = (OperationDepsNode *)rel->to;
-		BLI_assert(child->type == DEPSNODE_TYPE_OPERATION);
-		if (child->scheduled) {
-			/* Happens when having cyclic dependencies. */
-			continue;
-		}
-		schedule_node(pool, graph, layers, child, (rel->flag & DEPSREL_FLAG_CYCLIC) == 0, thread_id);
-	}
-}
-
-/**
- * Evaluate all nodes tagged for updating,
- * \warning This is usually done as part of main loop, but may also be
- * called from frame-change update.
- *
- * \note Time so

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list