diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-10-25 16:23:06 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-10-25 16:49:59 +0300 |
commit | fb896182b1f23c9b0e3e108458ec3aed390c6845 (patch) | |
tree | 41e56e5c0d809bbcfe055ba6c928f9c1eae16740 /source/blender/blenkernel/intern/scene.c | |
parent | 6b739bc2dcd5f4c6a84c72508608a63cfcc89dca (diff) |
Depsgraph; Introduce new scene update routines which gets an explicit graph
They are still modifying global state, such as ID recalc tags stored in bmain,
need some solution for this.
Diffstat (limited to 'source/blender/blenkernel/intern/scene.c')
-rw-r--r-- | source/blender/blenkernel/intern/scene.c | 145 |
1 files changed, 85 insertions, 60 deletions
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 72a953627ca..1736e824a94 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -1587,93 +1587,118 @@ static void prepare_mesh_for_viewport_render(Main *bmain, Scene *scene) } } -void BKE_scene_update_tagged(EvaluationContext *eval_ctx, Main *bmain, Scene *scene) +void BKE_scene_graph_update_tagged(EvaluationContext *eval_ctx, + Depsgraph *depsgraph, + Main *bmain, + Scene *scene) { - /* (re-)build dependency graph if needed */ - DEG_scene_relations_update(bmain, scene); - + /* TODO(sergey): Some functions here are changing global state, + * for example, clearing update tags from bmain. + */ + /* (Re-)build dependency graph if needed. */ + DEG_graph_relations_update(depsgraph, bmain, scene); /* Uncomment this to check if graph was properly tagged for update. */ - // DEG_debug_graph_relations_validate(scene->depsgraph_legacy, bmain, scene); - - /* flush editing data if needed */ + // DEG_debug_graph_relations_validate(depsgraph, bmain, scene); + /* Flush editing data if needed. */ prepare_mesh_for_viewport_render(bmain, scene); - - /* flush recalc flags to dependencies */ - DEG_graph_flush_update(bmain, scene->depsgraph_legacy); - - /* removed calls to quick_cache, see pointcache.c */ - - /* clear "LIB_TAG_DOIT" flag from all materials, to prevent infinite recursion problems later - * when trying to find materials with drivers that need evaluating [#32017] + /* Flush recalc flags to dependencies. */ + DEG_graph_flush_update(bmain, depsgraph); + /* Clear "LIB_TAG_DOIT" flag from all materials, to prevent infinite recursion problems later + * when trying to find materials with drivers that need evaluating [#32017]. */ BKE_main_id_tag_idcode(bmain, ID_MA, LIB_TAG_DOIT, false); BKE_main_id_tag_idcode(bmain, ID_LA, LIB_TAG_DOIT, false); - - /* update all objects: drivers, matrices, displists, etc. flags set + /* Update all objects: drivers, matrices, displists, etc. flags set * by depgraph or manual, no layer check here, gets correct flushed. */ - DEG_evaluate_on_refresh(eval_ctx, scene->depsgraph_legacy); - - /* update sound system animation (TODO, move to depsgraph) */ + DEG_evaluate_on_refresh(eval_ctx, depsgraph); + /* Update sound system animation (TODO, move to depsgraph). */ BKE_sound_update_scene(bmain, scene); - /* Inform editors about possible changes. */ DEG_ids_check_recalc(bmain, scene, false); - - /* clear recalc flags */ + /* Clear recalc flags. */ DEG_ids_clear_recalc(bmain); } /* applies changes right away, does all sets too */ -void BKE_scene_update_for_newframe(EvaluationContext *eval_ctx, Main *bmain, Scene *sce) +void BKE_scene_graph_update_for_newframe(EvaluationContext *eval_ctx, + Depsgraph *depsgraph, + Main *bmain, + Scene *scene) { - float ctime = BKE_scene_frame_get(sce); - - DEG_editors_update_pre(bmain, sce, true); - - /* keep this first */ - BLI_callback_exec(bmain, &sce->id, BLI_CB_EVT_FRAME_CHANGE_PRE); - - /* update animated image textures for particles, modifiers, gpu, etc, - * call this at the start so modifiers with textures don't lag 1 frame */ - BKE_image_update_frame(bmain, sce->r.cfra); - - BKE_sound_set_cfra(sce->r.cfra); - - /* clear animation overrides */ - /* XXX TODO... */ - - DEG_scene_relations_update(bmain, sce); - - /* Update animated cache files for modifiers. */ - BKE_cachefile_update_frame(bmain, sce, ctime, (((double)sce->r.frs_sec) / (double)sce->r.frs_sec_base)); - + /* TODO(sergey): Some functions here are changing global state, + * for example, clearing update tags from bmain. + */ + const float ctime = BKE_scene_frame_get(scene); + /* Inform editors we are starting scene update. */ + DEG_editors_update_pre(bmain, scene, true); + /* Keep this first. + * TODO(sergey): Should it be after the editors update? + */ + BLI_callback_exec(bmain, &scene->id, BLI_CB_EVT_FRAME_CHANGE_PRE); + /* Update animated image textures for particles, modifiers, gpu, etc, + * call this at the start so modifiers with textures don't lag 1 frame. + */ + BKE_image_update_frame(bmain, scene->r.cfra); + BKE_sound_set_cfra(scene->r.cfra); + DEG_graph_relations_update(depsgraph, bmain, scene); + /* Update animated cache files for modifiers. + * + * TODO(sergey): Make this a depsgraph node? + */ + BKE_cachefile_update_frame(bmain, scene, ctime, + (((double)scene->r.frs_sec) / (double)scene->r.frs_sec_base)); #ifdef POSE_ANIMATION_WORKAROUND scene_armature_depsgraph_workaround(bmain); #endif - - /* clear "LIB_TAG_DOIT" flag from all materials, to prevent infinite recursion problems later - * when trying to find materials with drivers that need evaluating [#32017] + /* Clear "LIB_TAG_DOIT" flag from all materials, to prevent infinite recursion problems later + * when trying to find materials with drivers that need evaluating [#32017]. */ BKE_main_id_tag_idcode(bmain, ID_MA, LIB_TAG_DOIT, false); BKE_main_id_tag_idcode(bmain, ID_LA, LIB_TAG_DOIT, false); - - /* BKE_object_handle_update() on all objects, groups and sets */ - DEG_evaluate_on_framechange(eval_ctx, bmain, sce->depsgraph_legacy, ctime); - - /* update sound system animation (TODO, move to depsgraph) */ - BKE_sound_update_scene(bmain, sce); - - /* notify editors and python about recalc */ - BLI_callback_exec(bmain, &sce->id, BLI_CB_EVT_FRAME_CHANGE_POST); - + /* Update all objects: drivers, matrices, displists, etc. flags set + * by depgraph or manual, no layer check here, gets correct flushed. + */ + DEG_evaluate_on_framechange(eval_ctx, bmain, depsgraph, ctime); + /* Update sound system animation (TODO, move to depsgraph). */ + BKE_sound_update_scene(bmain, scene); + /* Notify editors and python about recalc. */ + BLI_callback_exec(bmain, &scene->id, BLI_CB_EVT_FRAME_CHANGE_POST); /* Inform editors about possible changes. */ - DEG_ids_check_recalc(bmain, sce, true); - + DEG_ids_check_recalc(bmain, scene, true); /* clear recalc flags */ DEG_ids_clear_recalc(bmain); } +static void scene_ensure_legacy_depsgraph(Main *bmain, Scene *scene) +{ + if (scene->depsgraph_legacy == NULL) { + scene->depsgraph_legacy = DEG_graph_new(); + DEG_graph_build_from_scene(scene->depsgraph_legacy, bmain, scene); + /* TODO(sergey): When we first create dependency graph we consider + * it is first time became visible. This is true for viewports, but + * will fail when render engines will start having their own graphs. + */ + DEG_graph_on_visible_update(bmain, scene->depsgraph_legacy); + } +} + +void BKE_scene_update_tagged(EvaluationContext *eval_ctx, Main *bmain, Scene *scene) +{ + /* Make sure graph is allocated. This is not always guaranteed now. */ + scene_ensure_legacy_depsgraph(bmain, scene); + /* Do actual graph evaluation. */ + BKE_scene_graph_update_tagged(eval_ctx, scene->depsgraph_legacy, bmain, scene); +} + +void BKE_scene_update_for_newframe(EvaluationContext *eval_ctx, Main *bmain, Scene *scene) +{ + /* Make sure graph is allocated. This is not always guaranteed now. */ + scene_ensure_legacy_depsgraph(bmain, scene); + /* Do actual graph evaluation. */ + BKE_scene_graph_update_for_newframe(eval_ctx, scene->depsgraph_legacy, bmain, scene); +} + /* return default layer, also used to patch old files */ SceneRenderLayer *BKE_scene_add_render_layer(Scene *sce, const char *name) { |