diff options
author | Monique Dewanchand <mdewanchand> | 2022-09-14 22:33:51 +0300 |
---|---|---|
committer | Monique <mdewanchand@atmind.nl> | 2022-09-14 22:34:38 +0300 |
commit | 68589a31ebfb79165f99a979357d237e5413e904 (patch) | |
tree | a942e56d53f300b918ebf2597ee0895274d8e65a /source/blender/makesrna/intern/rna_scene.c | |
parent | 23276bcc37acc54f1e1814abdf482a432523c3a6 (diff) |
ViewLayer: Lazy sync of scene data.
When a change happens which invalidates view layers the syncing will be postponed until the first usage.
This will improve importing or adding many objects in a single operation/script.
`BKE_view_layer_need_resync_tag` is used to tag the view layer to be out of sync. Before accessing
`BKE_view_layer_active_base_get`, `BKE_view_layer_active_object_get`, `BKE_view_layer_active_collection`
or `BKE_view_layer_object_bases` the caller should call `BKE_view_layer_synced_ensure`.
Having two functions ensures that partial syncing could be added as smaller patches in the future. Tagging a
view layer out of sync could be replaced with a partial sync. Eventually the number of full resyncs could be
reduced. After all tagging has been replaced with partial syncs the ensure_sync could be phased out.
This patch has been added to discuss the details and consequences of the current approach. For clarity
the call to BKE_view_layer_ensure_sync is placed close to the getters.
In the future this could be placed in more strategical places to reduce the number of calls or improve
performance. Finding those strategical places isn't that clear. When multiple operations are grouped
in a single script you might want to always check for resync.
Some areas found that can be improved. This list isn't complete.
These areas aren't addressed by this patch as these changes would be hard to detect to the reviewer.
The idea is to add changes to these areas as a separate patch. It might be that the initial commit would reduce
performance compared to master, but will be fixed by the additional patches.
**Object duplication**
During object duplication the syncing is temporarily disabled. With this patch this isn't useful as when disabled
the view_layer is accessed to locate bases. This can be improved by first locating the source bases, then duplicate
and sync and locate the new bases. Will be solved in a separate patch for clarity reasons ({D15886}).
**Object add**
`BKE_object_add` not only adds a new object, but also selects and activates the new base. This requires the
view_layer to be resynced. Some callers reverse the selection and activation (See `get_new_constraint_target`).
We should make the selection and activation optional. This would make it possible to add multiple objects
without having to resync per object.
**Postpone Activate Base**
Setting the basact is done in many locations. They follow a rule as after an action find the base and set
the basact. Finding the base could require a resync. The idea is to store in the view_layer the object which
base will be set in the basact during the next sync, reducing the times resyncing needs to happen.
Reviewed By: mont29
Maniphest Tasks: T73411
Differential Revision: https://developer.blender.org/D15885
Diffstat (limited to 'source/blender/makesrna/intern/rna_scene.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_scene.c | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index e2b3276c45f..27cfe766eef 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -706,7 +706,9 @@ static void rna_GPencil_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UN static void rna_Gpencil_extend_selection(bContext *C, PointerRNA *UNUSED(ptr)) { /* Extend selection to all points in all selected strokes. */ + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); + BKE_view_layer_synced_ensure(scene, view_layer); Object *ob = BKE_view_layer_active_object_get(view_layer); if ((ob) && (ob->type == OB_GPENCIL)) { bGPdata *gpd = (bGPdata *)ob->data; @@ -1862,13 +1864,17 @@ static void rna_Scene_editmesh_select_mode_set(PointerRNA *ptr, const bool *valu /* Update select mode in all the workspaces in mesh edit mode. */ wmWindowManager *wm = G_MAIN->wm.first; LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { + const Scene *scene = WM_window_get_active_scene(win); ViewLayer *view_layer = WM_window_get_active_view_layer(win); - - if (view_layer && view_layer->basact) { - Mesh *me = BKE_mesh_from_object(view_layer->basact->object); - if (me && me->edit_mesh && me->edit_mesh->selectmode != flag) { - me->edit_mesh->selectmode = flag; - EDBM_selectmode_set(me->edit_mesh); + if (view_layer) { + BKE_view_layer_synced_ensure(scene, view_layer); + Object *object = BKE_view_layer_active_object_get(view_layer); + if (object) { + Mesh *me = BKE_mesh_from_object(object); + if (me && me->edit_mesh && me->edit_mesh->selectmode != flag) { + me->edit_mesh->selectmode = flag; + EDBM_selectmode_set(me->edit_mesh); + } } } } @@ -1877,11 +1883,14 @@ static void rna_Scene_editmesh_select_mode_set(PointerRNA *ptr, const bool *valu static void rna_Scene_editmesh_select_mode_update(bContext *C, PointerRNA *UNUSED(ptr)) { + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); Mesh *me = NULL; - if (view_layer->basact) { - me = BKE_mesh_from_object(view_layer->basact->object); + BKE_view_layer_synced_ensure(scene, view_layer); + Object *object = BKE_view_layer_active_object_get(view_layer); + if (object) { + me = BKE_mesh_from_object(object); if (me && me->edit_mesh == NULL) { me = NULL; } @@ -2220,11 +2229,14 @@ static char *rna_SequencerToolSettings_path(const PointerRNA *UNUSED(ptr)) /* generic function to recalc geometry */ static void rna_EditMesh_update(bContext *C, PointerRNA *UNUSED(ptr)) { + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); Mesh *me = NULL; - if (view_layer->basact) { - me = BKE_mesh_from_object(view_layer->basact->object); + BKE_view_layer_synced_ensure(scene, view_layer); + Object *object = BKE_view_layer_active_object_get(view_layer); + if (object) { + me = BKE_mesh_from_object(object); if (me && me->edit_mesh == NULL) { me = NULL; } @@ -2248,7 +2260,9 @@ static char *rna_MeshStatVis_path(const PointerRNA *UNUSED(ptr)) * given its own notifier. */ static void rna_Scene_update_active_object_data(bContext *C, PointerRNA *UNUSED(ptr)) { + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); + BKE_view_layer_synced_ensure(scene, view_layer); Object *ob = BKE_view_layer_active_object_get(view_layer); if (ob) { |