diff options
15 files changed, 97 insertions, 46 deletions
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index b27f7370ff4..596599deb75 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -2193,7 +2193,7 @@ Depsgraph *BKE_scene_get_depsgraph(Scene *scene, { *key_ptr = MEM_mallocN(sizeof(DepsgraphKey), __func__); **key_ptr = key; - *depsgraph_ptr = DEG_graph_new(); + *depsgraph_ptr = DEG_graph_new(scene, view_layer, DAG_EVAL_VIEWPORT); } depsgraph = *depsgraph_ptr; } diff --git a/source/blender/depsgraph/DEG_depsgraph.h b/source/blender/depsgraph/DEG_depsgraph.h index 43fb83e205b..9c00ed2ddcc 100644 --- a/source/blender/depsgraph/DEG_depsgraph.h +++ b/source/blender/depsgraph/DEG_depsgraph.h @@ -118,7 +118,9 @@ void DEG_depsgraph_enable_copy_on_write(void); /* Create new Depsgraph instance */ // TODO: what args are needed here? What's the building-graph entry point? -Depsgraph *DEG_graph_new(void); +Depsgraph *DEG_graph_new(struct Scene *scene, + struct ViewLayer *view_layer, + eEvaluationMode mode); /* Free Depsgraph itself and all its data */ void DEG_graph_free(Depsgraph *graph); diff --git a/source/blender/depsgraph/DEG_depsgraph_query.h b/source/blender/depsgraph/DEG_depsgraph_query.h index 8600022b7c3..ceba87338a0 100644 --- a/source/blender/depsgraph/DEG_depsgraph_query.h +++ b/source/blender/depsgraph/DEG_depsgraph_query.h @@ -49,6 +49,22 @@ struct ViewLayer; extern "C" { #endif +/* *********************** DEG input data ********************* */ + +/* Get scene that depsgraph was built for. */ +struct Scene *DEG_get_input_scene(const Depsgraph *graph); + +/* Get view layer that depsgraph was built for. */ +struct ViewLayer *DEG_get_input_view_layer(const Depsgraph *graph); + +/* Get evaluation mode that depsgraph was built for. */ +eEvaluationMode DEG_get_mode(const Depsgraph *graph); + +/* Get time that depsgraph is being evaluated or was last evaluated at. */ +float DEG_get_ctime(const Depsgraph *graph); + +/* ********************* DEG evaluated data ******************* */ + /* Check if given ID type was tagged for update. */ bool DEG_id_type_tagged(struct Main *bmain, short id_type); diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc index 339046dfac0..85f465efb82 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc @@ -127,8 +127,8 @@ void DepsgraphRelationBuilder::build_view_layer(Scene *scene, ViewLayer *view_la build_view_layer(scene->set, set_view_layer); } - graph_->scene = scene; - graph_->view_layer = view_layer; + BLI_assert(graph_->scene == scene); + BLI_assert(graph_->view_layer == view_layer); } } // namespace DEG diff --git a/source/blender/depsgraph/intern/depsgraph.cc b/source/blender/depsgraph/intern/depsgraph.cc index 3500f38467d..a87358187f2 100644 --- a/source/blender/depsgraph/intern/depsgraph.cc +++ b/source/blender/depsgraph/intern/depsgraph.cc @@ -49,6 +49,8 @@ extern "C" { #include "DNA_sequence_types.h" #include "RNA_access.h" + +#include "BKE_scene.h" } #include <algorithm> @@ -92,11 +94,15 @@ static void remove_from_vector(vector<T> *vector, const T& value) vector->end()); } -Depsgraph::Depsgraph() +Depsgraph::Depsgraph(Scene *scene, + ViewLayer *view_layer, + eEvaluationMode mode) : time_source(NULL), need_update(true), - scene(NULL), - view_layer(NULL) + scene(scene), + view_layer(view_layer), + mode(mode), + ctime(BKE_scene_frame_get(scene)) { BLI_spin_init(&lock); id_hash = BLI_ghash_ptr_new("Depsgraph id hash"); @@ -559,9 +565,14 @@ string deg_color_end(void) /* Public Graph API */ /* Initialize a new Depsgraph */ -Depsgraph *DEG_graph_new() -{ - DEG::Depsgraph *deg_depsgraph = OBJECT_GUARDED_NEW(DEG::Depsgraph); +Depsgraph *DEG_graph_new(Scene *scene, + ViewLayer *view_layer, + eEvaluationMode mode) +{ + DEG::Depsgraph *deg_depsgraph = OBJECT_GUARDED_NEW(DEG::Depsgraph, + scene, + view_layer, + mode); return reinterpret_cast<Depsgraph *>(deg_depsgraph); } diff --git a/source/blender/depsgraph/intern/depsgraph.h b/source/blender/depsgraph/intern/depsgraph.h index 985991e91e3..9fa6b38166d 100644 --- a/source/blender/depsgraph/intern/depsgraph.h +++ b/source/blender/depsgraph/intern/depsgraph.h @@ -38,6 +38,8 @@ #include "BLI_threads.h" /* for SpinLock */ +#include "DEG_depsgraph.h" + #include "intern/depsgraph_types.h" struct ID; @@ -100,7 +102,9 @@ struct Depsgraph { typedef vector<OperationDepsNode *> OperationNodes; typedef vector<IDDepsNode *> IDDepsNodes; - Depsgraph(); + Depsgraph(Scene *scene, + ViewLayer *view_layer, + eEvaluationMode mode); ~Depsgraph(); /** @@ -187,9 +191,13 @@ struct Depsgraph { */ SpinLock lock; - /* Scene and layer this dependency graph is built for. */ + /* Scene, layer, mode this dependency graph is built for. */ Scene *scene; ViewLayer *view_layer; + eEvaluationMode mode; + + /* Time at which dependency graph is being or was last evaluated. */ + float ctime; }; } // namespace DEG diff --git a/source/blender/depsgraph/intern/depsgraph_debug.cc b/source/blender/depsgraph/intern/depsgraph_debug.cc index e8d166532ad..78b1c6f88c5 100644 --- a/source/blender/depsgraph/intern/depsgraph_debug.cc +++ b/source/blender/depsgraph/intern/depsgraph_debug.cc @@ -37,9 +37,12 @@ extern "C" { #include "DNA_scene_types.h" } /* extern "C" */ +#include "DNA_object_types.h" + #include "DEG_depsgraph.h" #include "DEG_depsgraph_debug.h" #include "DEG_depsgraph_build.h" +#include "DEG_depsgraph_query.h" #include "intern/depsgraph_intern.h" #include "intern/nodes/deg_node_id.h" @@ -72,7 +75,7 @@ bool DEG_debug_graph_relations_validate(Depsgraph *graph, Scene *scene, ViewLayer *view_layer) { - Depsgraph *temp_depsgraph = DEG_graph_new(); + Depsgraph *temp_depsgraph = DEG_graph_new(scene, view_layer, DEG_get_mode(graph)); bool valid = true; DEG_graph_build_from_view_layer(temp_depsgraph, bmain, scene, view_layer); if (!DEG_debug_compare(temp_depsgraph, graph)) { diff --git a/source/blender/depsgraph/intern/depsgraph_eval.cc b/source/blender/depsgraph/intern/depsgraph_eval.cc index 0b3e4fd8db9..d50e55e4cfb 100644 --- a/source/blender/depsgraph/intern/depsgraph_eval.cc +++ b/source/blender/depsgraph/intern/depsgraph_eval.cc @@ -134,9 +134,10 @@ void DEG_evaluate_on_refresh(EvaluationContext *eval_ctx, Depsgraph *graph) { DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph); + deg_graph->ctime = BKE_scene_frame_get(deg_graph->scene); /* Update time on primary timesource. */ DEG::TimeSourceDepsNode *tsrc = deg_graph->find_time_source(); - tsrc->cfra = BKE_scene_frame_get(deg_graph->scene); + tsrc->cfra = deg_graph->ctime; DEG::deg_evaluate_on_refresh(eval_ctx, deg_graph); } @@ -147,6 +148,7 @@ void DEG_evaluate_on_framechange(EvaluationContext *eval_ctx, float ctime) { DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph); + deg_graph->ctime = ctime; /* Update time on primary timesource. */ DEG::TimeSourceDepsNode *tsrc = deg_graph->find_time_source(); tsrc->cfra = ctime; diff --git a/source/blender/depsgraph/intern/depsgraph_query.cc b/source/blender/depsgraph/intern/depsgraph_query.cc index 4e70e56ae71..6f0ba26c8f7 100644 --- a/source/blender/depsgraph/intern/depsgraph_query.cc +++ b/source/blender/depsgraph/intern/depsgraph_query.cc @@ -49,6 +49,31 @@ extern "C" { #include "intern/depsgraph_intern.h" #include "intern/nodes/deg_node_id.h" +struct Scene *DEG_get_input_scene(const Depsgraph *graph) +{ + const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph); + return deg_graph->scene; +} + +struct ViewLayer *DEG_get_input_view_layer(const Depsgraph *graph) +{ + const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph); + return deg_graph->view_layer; +} + +eEvaluationMode DEG_get_mode(const Depsgraph *graph) +{ + const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph); + return deg_graph->mode; +} + +float DEG_get_ctime(const Depsgraph *graph) +{ + const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph); + return deg_graph->ctime; +} + + bool DEG_id_type_tagged(Main *bmain, short id_type) { return bmain->id_tag_update[BKE_idcode_to_index(id_type)] != 0; diff --git a/source/blender/depsgraph/intern/depsgraph_tag.cc b/source/blender/depsgraph/intern/depsgraph_tag.cc index d1de12f4591..6a6ebd1be44 100644 --- a/source/blender/depsgraph/intern/depsgraph_tag.cc +++ b/source/blender/depsgraph/intern/depsgraph_tag.cc @@ -425,20 +425,6 @@ void deg_graph_id_tag_update(Main *bmain, Depsgraph *graph, ID *id, int flag) id_tag_update_ntree_special(bmain, graph, id, flag); } -/* TODO(sergey): Consider storing scene and view layer at depsgraph allocation - * time. - */ -void deg_ensure_scene_view_layer(Depsgraph *graph, - Scene *scene, - ViewLayer *view_layer) -{ - if (!graph->need_update) { - return; - } - graph->scene = scene; - graph->view_layer = view_layer; -} - void deg_id_tag_update(Main *bmain, ID *id, int flag) { deg_graph_id_tag_update(bmain, NULL, id, flag); @@ -449,11 +435,6 @@ void deg_id_tag_update(Main *bmain, ID *id, int flag) view_layer, false); if (depsgraph != NULL) { - /* Make sure depsgraph is pointing to a correct scene and - * view layer. This is mainly required in cases when depsgraph - * was not built yet. - */ - deg_ensure_scene_view_layer(depsgraph, scene, view_layer); deg_graph_id_tag_update(bmain, depsgraph, id, flag); } } diff --git a/source/blender/editors/object/object_bake_api.c b/source/blender/editors/object/object_bake_api.c index 0fde6f643a8..1c882fda5d5 100644 --- a/source/blender/editors/object/object_bake_api.c +++ b/source/blender/editors/object/object_bake_api.c @@ -646,7 +646,7 @@ static int bake( const char *identifier, ScrArea *sa, const char *uv_layer) { EvaluationContext *eval_ctx = DEG_evaluation_context_new(DAG_EVAL_RENDER); - Depsgraph *depsgraph = DEG_graph_new(); + Depsgraph *depsgraph = DEG_graph_new(scene, view_layer, DAG_EVAL_RENDER); DEG_evaluation_context_init_from_view_layer_for_render(eval_ctx, depsgraph, scene, view_layer); int op_result = OPERATOR_CANCELLED; diff --git a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp index b159bade13d..3935c724d11 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp +++ b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp @@ -79,11 +79,11 @@ NodeGroup *BlenderFileLoader::Load() _z_offset = 0.f; } - EvaluationContext *eval_ctx = DEG_evaluation_context_new(DAG_EVAL_RENDER); - Depsgraph *depsgraph = DEG_graph_new(); - ViewLayer *view_layer = (ViewLayer*)BLI_findstring(&_re->scene->view_layers, _view_layer->name, offsetof(ViewLayer, name)); + EvaluationContext *eval_ctx = DEG_evaluation_context_new(DAG_EVAL_RENDER); + Depsgraph *depsgraph = DEG_graph_new(_re->scene, view_layer, DAG_EVAL_RENDER); + DEG_evaluation_context_init_from_view_layer_for_render( eval_ctx, depsgraph, diff --git a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp index 62be648bba3..8aac83a6179 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp +++ b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp @@ -77,7 +77,6 @@ const char *BlenderStrokeRenderer::uvNames[] = {"along_stroke", "along_stroke_ti BlenderStrokeRenderer::BlenderStrokeRenderer(Render *re, int render_count) : StrokeRenderer() { freestyle_bmain = re->freestyle_bmain; - freestyle_depsgraph = DEG_graph_new(); // for stroke mesh generation _width = re->winx; @@ -142,7 +141,6 @@ BlenderStrokeRenderer::BlenderStrokeRenderer(Render *re, int render_count) : Str } BKE_scene_set_background(freestyle_bmain, freestyle_scene); - DEG_graph_id_tag_update(freestyle_bmain, freestyle_depsgraph, &freestyle_scene->id, 0); // Scene layer. ViewLayer *view_layer = (ViewLayer *)freestyle_scene->view_layers.first; @@ -150,7 +148,6 @@ BlenderStrokeRenderer::BlenderStrokeRenderer(Render *re, int render_count) : Str // Camera Object *object_camera = BKE_object_add(freestyle_bmain, freestyle_scene, view_layer, OB_CAMERA, NULL); - DEG_graph_id_tag_update(freestyle_bmain, freestyle_depsgraph, &object_camera->id, 0); Camera *camera = (Camera *)object_camera->data; camera->type = CAM_ORTHO; @@ -179,7 +176,10 @@ BlenderStrokeRenderer::BlenderStrokeRenderer(Render *re, int render_count) : Str else _nodetree_hash = NULL; - // New IDs were added, tag relations for update. + // Depsgraph + freestyle_depsgraph = DEG_graph_new(re->scene, view_layer, DAG_EVAL_RENDER); + DEG_graph_id_tag_update(freestyle_bmain, freestyle_depsgraph, &freestyle_scene->id, 0); + DEG_graph_id_tag_update(freestyle_bmain, freestyle_depsgraph, &object_camera->id, 0); DEG_graph_tag_relations_update(freestyle_depsgraph); } diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c index 003c69ccbd4..bb5e68ff3ad 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -5948,7 +5948,7 @@ void RE_Database_Baking(Render *re, Main *bmain, Scene *scene, ViewLayer *view_l RE_init_threadcount(re); EvaluationContext *eval_ctx = DEG_evaluation_context_new(DAG_EVAL_RENDER); - Depsgraph *depsgraph = DEG_graph_new(); + Depsgraph *depsgraph = DEG_graph_new(scene, view_layer, DAG_EVAL_RENDER); DEG_evaluation_context_init_from_view_layer_for_render(eval_ctx, depsgraph, scene, view_layer); DEG_graph_build_from_view_layer(depsgraph, bmain, scene, view_layer); BKE_scene_graph_update_tagged(eval_ctx, diff --git a/source/blender/render/intern/source/external_engine.c b/source/blender/render/intern/source/external_engine.c index 617e49c5d0f..15c8d0d524d 100644 --- a/source/blender/render/intern/source/external_engine.c +++ b/source/blender/render/intern/source/external_engine.c @@ -530,21 +530,24 @@ RenderData *RE_engine_get_render_data(Render *re) /* Depsgraph */ static void engine_depsgraph_init(RenderEngine *engine, ViewLayer *view_layer) { + Main *bmain = engine->re->main; + Scene *scene = engine->re->scene; + engine->eval_ctx = DEG_evaluation_context_new(DAG_EVAL_RENDER); - engine->depsgraph = DEG_graph_new(); + engine->depsgraph = DEG_graph_new(scene, view_layer, DAG_EVAL_RENDER); engine->view_layer = view_layer; DEG_evaluation_context_init_from_view_layer_for_render( engine->eval_ctx, engine->depsgraph, - engine->re->scene, + scene, view_layer); BKE_scene_graph_update_tagged( engine->eval_ctx, engine->depsgraph, - engine->re->main, - engine->re->scene, + bmain, + scene, view_layer); } |