Merge remote-tracking branch 'origin/master' into blender2.8
authorDalai Felinto <dfelinto@gmail.com>
Thu, 29 Mar 2018 13:36:34 +0000 (10:36 -0300)
committerDalai Felinto <dfelinto@gmail.com>
Thu, 29 Mar 2018 13:36:34 +0000 (10:36 -0300)
Fix for T54437: Sequencer preview uses last updated scene

The fix started in master, moving EvaluationContext initialization
before we leave `deg_evaluate_on_refresh()`.

Upon merging master we can fix the actual issue which was to set
the EvaluationContext depsgraph even if the depsgraph was already updated.

1  2 
source/blender/depsgraph/intern/eval/deg_eval.cc

index f3b45303e35a59844b975bbc856ba00acde2f3b6,fc71b5ccb7baba8e5bf5bbd24e0e0ab39ea84719..1355e68097b4b65e2ba70cccfffd1d502e0cd3c0
  #include "BLI_task.h"
  #include "BLI_ghash.h"
  
 -extern "C" {
 -#include "BKE_depsgraph.h"
 -#include "BKE_global.h"
 -} /* extern "C" */
 +#include "DNA_object_types.h"
  
  #include "DEG_depsgraph.h"
 +#include "DEG_depsgraph_query.h"
  
  #include "atomic_ops.h"
  
@@@ -66,11 -68,13 +66,11 @@@ namespace DEG 
  static void schedule_children(TaskPool *pool,
                                Depsgraph *graph,
                                OperationDepsNode *node,
 -                              const unsigned int layers,
                                const int thread_id);
  
  struct DepsgraphEvalState {
        EvaluationContext *eval_ctx;
        Depsgraph *graph;
 -      unsigned int layers;
        bool do_stats;
  };
  
@@@ -94,12 -98,13 +94,12 @@@ static void deg_task_run_func(TaskPool 
        }
        /* Schedule children. */
        BLI_task_pool_delayed_push_begin(pool, thread_id);
 -      schedule_children(pool, state->graph, node, state->layers, thread_id);
 +      schedule_children(pool, state->graph, node, thread_id);
        BLI_task_pool_delayed_push_end(pool, thread_id);
  }
  
  typedef struct CalculatePengindData {
        Depsgraph *graph;
 -      unsigned int layers;
  } CalculatePengindData;
  
  static void calculate_pending_func(
  {
        CalculatePengindData *data = (CalculatePengindData *)data_v;
        Depsgraph *graph = data->graph;
 -      unsigned 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)
 -      {
 +      if ((node->flag & DEPSOP_FLAG_NEEDS_UPDATE) != 0) {
                foreach (DepsRelation *rel, node->inlinks) {
                        if (rel->from->type == DEG_NODE_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)
 -                              {
 +                              if ((from->flag & DEPSOP_FLAG_NEEDS_UPDATE) != 0) {
                                        ++node->num_links_pending;
                                }
                        }
        }
  }
  
 -static void calculate_pending_parents(Depsgraph *graph, unsigned int layers)
 +static void calculate_pending_parents(Depsgraph *graph)
  {
        const int num_operations = graph->operations.size();
        CalculatePengindData data;
        data.graph = graph;
 -      data.layers = layers;
        ParallelRangeSettings settings;
        BLI_parallel_range_settings_defaults(&settings);
        settings.min_iter_per_thread = 1024;
  static void initialize_execution(DepsgraphEvalState *state, Depsgraph *graph)
  {
        const bool do_stats = state->do_stats;
 -      calculate_pending_parents(graph, state->layers);
 +      calculate_pending_parents(graph);
        /* Clear tags and other things which needs to be clear. */
        foreach (OperationDepsNode *node, graph->operations) {
                node->done = 0;
   *   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, unsigned int layers,
 +static void schedule_node(TaskPool *pool, Depsgraph *graph,
                            OperationDepsNode *node, bool dec_parents,
                            const int thread_id)
  {
 -      unsigned int id_layers = node->owner->owner->layers;
 -
 -      if ((node->flag & DEPSOP_FLAG_NEEDS_UPDATE) != 0 &&
 -          (id_layers & layers) != 0)
 -      {
 +      if ((node->flag & DEPSOP_FLAG_NEEDS_UPDATE) != 0) {
                if (dec_parents) {
                        BLI_assert(node->num_links_pending > 0);
                        atomic_sub_and_fetch_uint32(&node->num_links_pending, 1);
                        if (!is_scheduled) {
                                if (node->is_noop()) {
                                        /* skip NOOP node, schedule children right away */
 -                                      schedule_children(pool, graph, node, layers, thread_id);
 +                                      schedule_children(pool, graph, node, thread_id);
                                }
                                else {
                                        /* children are scheduled once this task is completed */
        }
  }
  
 -static void schedule_graph(TaskPool *pool,
 -                           Depsgraph *graph,
 -                           const unsigned int layers)
 +static void schedule_graph(TaskPool *pool, Depsgraph *graph)
  {
        foreach (OperationDepsNode *node, graph->operations) {
 -              schedule_node(pool, graph, layers, node, false, 0);
 +              schedule_node(pool, graph, node, false, 0);
        }
  }
  
  static void schedule_children(TaskPool *pool,
                                Depsgraph *graph,
                                OperationDepsNode *node,
 -                              const unsigned int layers,
                                const int thread_id)
  {
        foreach (DepsRelation *rel, node->outlinks) {
                }
                schedule_node(pool,
                              graph,
 -                            layers,
                              child,
                              (rel->flag & DEPSREL_FLAG_CYCLIC) == 0,
                              thread_id);
   * \note Time sources should be all valid!
   */
  void deg_evaluate_on_refresh(EvaluationContext *eval_ctx,
 -                             Depsgraph *graph,
 -                             const unsigned int layers)
 +                             Depsgraph *graph)
  {
+       /* Set time for the current graph evaluation context. */
+       TimeSourceDepsNode *time_src = graph->find_time_source();
+       eval_ctx->ctime = time_src->cfra;
++      eval_ctx->depsgraph = (::Depsgraph *)graph;
++      eval_ctx->view_layer = DEG_get_evaluated_view_layer((::Depsgraph *)graph);
        /* Nothing to update, early out. */
        if (BLI_gset_len(graph->entry_tags) == 0) {
                return;
        }
 -      DEG_DEBUG_PRINTF(EVAL, "%s: layers:%u, graph->layers:%u\n",
 -                       __func__,
 -                       layers,
 -                       graph->layers);
        const bool do_time_debug = ((G.debug & G_DEBUG_DEPSGRAPH_TIME) != 0);
        const double start_time = do_time_debug ? PIL_check_seconds_timer() : 0;
-       /* Set time for the current graph evaluation context. */
-       TimeSourceDepsNode *time_src = graph->find_time_source();
-       eval_ctx->depsgraph = (::Depsgraph *)graph;
-       eval_ctx->view_layer = DEG_get_evaluated_view_layer((::Depsgraph *)graph);
-       eval_ctx->ctime = time_src->cfra;
        /* Set up evaluation context for depsgraph itself. */
        DepsgraphEvalState state;
        state.eval_ctx = eval_ctx;
        state.graph = graph;
 -      state.layers = layers;
        state.do_stats = do_time_debug;
        /* Set up task scheduler and pull for threaded evaluation. */
        TaskScheduler *task_scheduler;
        /* Prepare all nodes for evaluation. */
        initialize_execution(&state, graph);
        /* Do actual evaluation now. */
 -      schedule_graph(task_pool, graph, layers);
 +      schedule_graph(task_pool, graph);
        BLI_task_pool_work_and_wait(task_pool);
        BLI_task_pool_free(task_pool);
        /* Finalize statistics gathering. This is because we only gather single