Depsgraph: Ensure we only expand scene datablock on evaluation

Previously it could have happened on every request to evaluated scene
or view layer.

This commit also removes expansion of view layer and scene from iterator.
Iterator is not to be used before depsgraph is evaluated.
This commit is contained in:
Sergey Sharybin 2018-04-25 15:02:22 +02:00
parent 09da47b67a
commit 29631ff013
3 changed files with 23 additions and 24 deletions

View File

@ -110,6 +110,7 @@ Scene *DEG_get_evaluated_scene(const Depsgraph *graph)
* that calleer is OK with just a pointer in case scene is not up[dated
* yet?
*/
BLI_assert(DEG::deg_copy_on_write_is_expanded(&scene_cow->id));
return scene_cow;
}
@ -118,19 +119,6 @@ ViewLayer *DEG_get_evaluated_view_layer(const Depsgraph *graph)
const DEG::Depsgraph *deg_graph =
reinterpret_cast<const DEG::Depsgraph *>(graph);
Scene *scene_cow = DEG_get_evaluated_scene(graph);
/* We update copy-on-write scene in the following cases:
* - It was not expanded yet.
* - It was tagged for update of CoW component.
* This allows us to have proper view layer pointer.
*/
if (DEG_depsgraph_use_copy_on_write() &&
(!DEG::deg_copy_on_write_is_expanded(&scene_cow->id) ||
scene_cow->id.recalc & ID_RECALC_COPY_ON_WRITE))
{
const DEG::IDDepsNode *id_node =
deg_graph->find_id_node(&deg_graph->scene->id);
DEG::deg_update_copy_on_write_datablock(deg_graph, id_node);
}
/* Do name-based lookup. */
/* TODO(sergey): Can this be optimized? */
ViewLayer *view_layer_orig = deg_graph->view_layer;

View File

@ -209,11 +209,6 @@ void DEG_iterator_objects_begin(BLI_Iterator *iter, DEGObjectIterData *data)
return;
}
/* TODO: Calling this forces the scene datablock to be expanded,
* otherwise we get crashes on load with copy-on-write. There may
* be a better solution for this. */
DEG_get_evaluated_view_layer(depsgraph);
iter->data = data;
data->dupli_parent = NULL;
data->dupli_list = NULL;

View File

@ -39,12 +39,14 @@
#include "BLI_ghash.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_query.h"
#include "atomic_ops.h"
#include "intern/eval/deg_eval_copy_on_write.h"
#include "intern/eval/deg_eval_flush.h"
#include "intern/eval/deg_eval_stats.h"
#include "intern/nodes/deg_node.h"
@ -219,6 +221,25 @@ static void schedule_children(TaskPool *pool,
}
}
static void depsgraph_ensure_view_layer(Depsgraph *graph)
{
/* We update copy-on-write scene in the following cases:
* - It was not expanded yet.
* - It was tagged for update of CoW component.
* This allows us to have proper view layer pointer.
*/
if (!DEG_depsgraph_use_copy_on_write()) {
return;
}
Scene *scene_cow = graph->scene_cow;
if (!deg_copy_on_write_is_expanded(&scene_cow->id) ||
scene_cow->id.recalc & ID_RECALC_COPY_ON_WRITE)
{
const IDDepsNode *id_node = graph->find_id_node(&graph->scene->id);
deg_update_copy_on_write_datablock(graph, id_node);
}
}
/**
* Evaluate all nodes tagged for updating,
* \warning This is usually done as part of main loop, but may also be
@ -234,12 +255,7 @@ void deg_evaluate_on_refresh(Depsgraph *graph)
}
const bool do_time_debug = ((G.debug & G_DEBUG_DEPSGRAPH_TIME) != 0);
const double start_time = do_time_debug ? PIL_check_seconds_timer() : 0;
/* TODO: Calling this forces the scene datablock to be expanded,
* otherwise we get crashes on load with copy-on-write. There may
* be a better solution for this. */
DEG_get_evaluated_view_layer((const ::Depsgraph*)graph);
depsgraph_ensure_view_layer(graph);
/* Set up evaluation state. */
DepsgraphEvalState state;
state.graph = graph;