Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonique Dewanchand <mdewanchand>2022-09-14 22:33:51 +0300
committerMonique <mdewanchand@atmind.nl>2022-09-14 22:34:38 +0300
commit68589a31ebfb79165f99a979357d237e5413e904 (patch)
treea942e56d53f300b918ebf2597ee0895274d8e65a /source/blender/blenkernel/intern/scene.cc
parent23276bcc37acc54f1e1814abdf482a432523c3a6 (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/blenkernel/intern/scene.cc')
-rw-r--r--source/blender/blenkernel/intern/scene.cc52
1 files changed, 31 insertions, 21 deletions
diff --git a/source/blender/blenkernel/intern/scene.cc b/source/blender/blenkernel/intern/scene.cc
index 96be505d214..db950492f69 100644
--- a/source/blender/blenkernel/intern/scene.cc
+++ b/source/blender/blenkernel/intern/scene.cc
@@ -803,8 +803,8 @@ static void scene_foreach_id(ID *id, LibraryForeachIDData *data)
LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, view_layer->mat_override, IDWALK_CB_USER);
-
- LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
+ BKE_view_layer_synced_ensure(scene, view_layer);
+ LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(view_layer)) {
BKE_LIB_FOREACHID_PROCESS_IDSUPER(
data, base->object, IDWALK_CB_NOP | IDWALK_CB_OVERRIDE_LIBRARY_NOT_OVERRIDABLE);
}
@@ -2050,7 +2050,8 @@ Scene *BKE_scene_add(Main *bmain, const char *name)
bool BKE_scene_object_find(Scene *scene, Object *ob)
{
LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
- if (BLI_findptr(&view_layer->object_bases, ob, offsetof(Base, object))) {
+ BKE_view_layer_synced_ensure(scene, view_layer);
+ if (BLI_findptr(BKE_view_layer_object_bases_get(view_layer), ob, offsetof(Base, object))) {
return true;
}
}
@@ -2060,7 +2061,8 @@ bool BKE_scene_object_find(Scene *scene, Object *ob)
Object *BKE_scene_object_find_by_name(const Scene *scene, const char *name)
{
LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
- LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
+ BKE_view_layer_synced_ensure(scene, view_layer);
+ LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(view_layer)) {
if (STREQ(base->object->id.name + 2, name)) {
return base->object;
}
@@ -2081,7 +2083,8 @@ void BKE_scene_set_background(Main *bmain, Scene *scene)
/* copy layers and flags from bases to objects */
LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
- LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
+ BKE_view_layer_synced_ensure(scene, view_layer);
+ LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(view_layer)) {
/* collection patch... */
BKE_scene_object_base_flag_sync_from_base(base);
}
@@ -2124,7 +2127,8 @@ int BKE_scene_base_iter_next(
if (iter->phase == F_START) {
ViewLayer *view_layer = (depsgraph) ? DEG_get_evaluated_view_layer(depsgraph) :
BKE_view_layer_context_active_PLACEHOLDER(*scene);
- *base = static_cast<Base *>(view_layer->object_bases.first);
+ BKE_view_layer_synced_ensure(*scene, view_layer);
+ *base = static_cast<Base *>(BKE_view_layer_object_bases_get(view_layer)->first);
if (*base) {
*ob = (*base)->object;
iter->phase = F_SCENE;
@@ -2134,8 +2138,10 @@ int BKE_scene_base_iter_next(
while ((*scene)->set) {
(*scene) = (*scene)->set;
ViewLayer *view_layer_set = BKE_view_layer_default_render(*scene);
- if (view_layer_set->object_bases.first) {
- *base = static_cast<Base *>(view_layer_set->object_bases.first);
+ BKE_view_layer_synced_ensure(*scene, view_layer_set);
+ ListBase *object_bases = BKE_view_layer_object_bases_get(view_layer_set);
+ if (object_bases->first) {
+ *base = static_cast<Base *>(object_bases->first);
*ob = (*base)->object;
iter->phase = F_SCENE;
break;
@@ -2155,8 +2161,10 @@ int BKE_scene_base_iter_next(
while ((*scene)->set) {
(*scene) = (*scene)->set;
ViewLayer *view_layer_set = BKE_view_layer_default_render(*scene);
- if (view_layer_set->object_bases.first) {
- *base = static_cast<Base *>(view_layer_set->object_bases.first);
+ BKE_view_layer_synced_ensure(*scene, view_layer_set);
+ ListBase *object_bases = BKE_view_layer_object_bases_get(view_layer_set);
+ if (object_bases->first) {
+ *base = static_cast<Base *>(object_bases->first);
*ob = (*base)->object;
break;
}
@@ -2505,7 +2513,9 @@ static bool check_rendered_viewport_visible(Main *bmain)
/* TODO(@campbellbarton): shouldn't we be able to use 'DEG_get_view_layer' here?
* Currently this is nullptr on load, so don't. */
-static void prepare_mesh_for_viewport_render(Main *bmain, const ViewLayer *view_layer)
+static void prepare_mesh_for_viewport_render(Main *bmain,
+ const Scene *scene,
+ ViewLayer *view_layer)
{
/* This is needed to prepare mesh to be used by the render
* engine from the viewport rendering. We do loading here
@@ -2515,7 +2525,7 @@ static void prepare_mesh_for_viewport_render(Main *bmain, const ViewLayer *view_
* This makes it so viewport render engine doesn't need to
* call loading of the edit data for the mesh objects.
*/
-
+ BKE_view_layer_synced_ensure(scene, view_layer);
Object *obedit = BKE_view_layer_edit_object_get(view_layer);
if (obedit) {
Mesh *mesh = static_cast<Mesh *>(obedit->data);
@@ -2592,7 +2602,7 @@ static void scene_graph_update_tagged(Depsgraph *depsgraph, Main *bmain, bool on
/* Uncomment this to check if graph was properly tagged for update. */
// DEG_debug_graph_relations_validate(depsgraph, bmain, scene);
/* Flush editing data if needed. */
- prepare_mesh_for_viewport_render(bmain, view_layer);
+ prepare_mesh_for_viewport_render(bmain, scene, view_layer);
/* Update all objects: drivers, matrices, etc. flags set
* by depsgraph or manual, no layer check here, gets correct flushed. */
DEG_evaluate_on_refresh(depsgraph);
@@ -2810,8 +2820,10 @@ Base *_setlooper_base_step(Scene **sce_iter, ViewLayer *view_layer, Base *base)
if ((base == nullptr) && (view_layer != nullptr)) {
/* First time looping, return the scenes first base. */
/* For the first loop we should get the layer from workspace when available. */
- if (view_layer->object_bases.first) {
- return (Base *)view_layer->object_bases.first;
+ BKE_view_layer_synced_ensure(*sce_iter, view_layer);
+ ListBase *object_bases = BKE_view_layer_object_bases_get(view_layer);
+ if (object_bases->first) {
+ return static_cast<Base *>(object_bases->first);
}
/* No base on this scene layer. */
goto next_set;
@@ -2821,7 +2833,7 @@ Base *_setlooper_base_step(Scene **sce_iter, ViewLayer *view_layer, Base *base)
/* Reached the end, get the next base in the set. */
while ((*sce_iter = (*sce_iter)->set)) {
ViewLayer *view_layer_set = BKE_view_layer_default_render(*sce_iter);
- base = (Base *)view_layer_set->object_bases.first;
+ base = (Base *)BKE_view_layer_object_bases_get(view_layer_set)->first;
if (base) {
return base;
@@ -2880,13 +2892,11 @@ bool BKE_scene_uses_cycles_experimental_features(Scene *scene)
return RNA_enum_get(&cycles_ptr, "feature_set") == CYCLES_FEATURES_EXPERIMENTAL;
}
-void BKE_scene_base_flag_to_objects(const Scene *UNUSED(scene), ViewLayer *view_layer)
+void BKE_scene_base_flag_to_objects(const Scene *scene, ViewLayer *view_layer)
{
- Base *base = static_cast<Base *>(view_layer->object_bases.first);
-
- while (base) {
+ BKE_view_layer_synced_ensure(scene, view_layer);
+ LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(view_layer)) {
BKE_scene_object_base_flag_sync_from_base(base);
- base = base->next;
}
}