[Bf-blender-cvs] [4674e025626] master: Depsgraph: Only bind ID-data and indices to depsgraph callbacks

Sergey Sharybin noreply at git.blender.org
Wed Apr 4 09:49:24 CEST 2018


Commit: 4674e02562637f36a9900bff5f5f4acc9aff482d
Author: Sergey Sharybin
Date:   Tue Apr 3 17:23:43 2018 +0200
Branches: master
https://developer.blender.org/rB4674e02562637f36a9900bff5f5f4acc9aff482d

Depsgraph: Only bind ID-data and indices to depsgraph callbacks

This is a part of copy-on-write sanitization, to avoid all the checks
which were attempting to keep sub-data pointers intact.

Point is: ID pointers never change for CoW datablocks, but nested
data pointers might change when updating existing copy.

Solution: Only bind ID data pointers and index of sub-data.
This will make CoW datablock 7update function was easier in 2.8.

In master we were only using pose channel pointers in callbacks,
this is exactly what this commit addresses. A linear lookup array
is created on pose evaluation init and is thrown away afterwards.

One thing we might consider doing is to keep indexed array of
poses, similar to chanhash.

Reviewers: campbellbarton

Reviewed By: campbellbarton

Subscribers: dfelinto

Differential Revision: https://developer.blender.org/D3124

===================================================================

M	source/blender/blenkernel/BKE_armature.h
M	source/blender/blenkernel/intern/armature_update.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/depsgraph/intern/builder/deg_builder_nodes.h
M	source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc
M	source/blender/makesdna/DNA_action_types.h

===================================================================

diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h
index 60fb79d75d5..f6de39c897e 100644
--- a/source/blender/blenkernel/BKE_armature.h
+++ b/source/blender/blenkernel/BKE_armature.h
@@ -169,41 +169,39 @@ void BKE_splineik_execute_tree(struct Scene *scene, struct Object *ob, struct bP
 
 void BKE_pose_eval_init(struct EvaluationContext *eval_ctx,
                         struct Scene *scene,
-                        struct Object *ob,
-                        struct bPose *pose);
+                        struct Object *ob);
 
 void BKE_pose_eval_init_ik(struct EvaluationContext *eval_ctx,
                            struct Scene *scene,
-                           struct Object *ob,
-                           struct bPose *pose);
+                           struct Object *ob);
 
 void BKE_pose_eval_bone(struct EvaluationContext *eval_ctx,
                         struct Scene *scene,
                         struct Object *ob,
-                        struct bPoseChannel *pchan);
+                        int pchan_index);
 
 void BKE_pose_constraints_evaluate(struct EvaluationContext *eval_ctx,
                                    struct Scene *scene,
                                    struct Object *ob,
-                                   struct bPoseChannel *pchan);
+                                   int pchan_index);
 
 void BKE_pose_bone_done(struct EvaluationContext *eval_ctx,
-                        struct bPoseChannel *pchan);
+                        struct Object *ob,
+                        int pchan_index);
 
 void BKE_pose_iktree_evaluate(struct EvaluationContext *eval_ctx,
                               struct Scene *scene,
                               struct Object *ob,
-                              struct bPoseChannel *rootchan);
+                              int rootchan_index);
 
 void BKE_pose_splineik_evaluate(struct EvaluationContext *eval_ctx,
                                 struct Scene *scene,
                                 struct Object *ob,
-                                struct bPoseChannel *rootchan);
+                                int rootchan_index);
 
 void BKE_pose_eval_flush(struct EvaluationContext *eval_ctx,
                          struct Scene *scene,
-                         struct Object *ob,
-                         struct bPose *pose);
+                         struct Object *ob);
 
 void BKE_pose_eval_proxy_copy(struct EvaluationContext *eval_ctx,
                               struct Object *ob);
diff --git a/source/blender/blenkernel/intern/armature_update.c b/source/blender/blenkernel/intern/armature_update.c
index 56e9cce1825..95a26814e37 100644
--- a/source/blender/blenkernel/intern/armature_update.c
+++ b/source/blender/blenkernel/intern/armature_update.c
@@ -553,10 +553,10 @@ void BKE_splineik_execute_tree(Scene *scene, Object *ob, bPoseChannel *pchan_roo
 
 void BKE_pose_eval_init(EvaluationContext *UNUSED(eval_ctx),
                         Scene *UNUSED(scene),
-                        Object *ob,
-                        bPose *pose)
+                        Object *ob)
 {
-	bPoseChannel *pchan;
+	bPose *pose = ob->pose;
+	BLI_assert(pose != NULL);
 
 	DEG_debug_print_eval(__func__, ob->id.name, ob);
 
@@ -569,16 +569,21 @@ void BKE_pose_eval_init(EvaluationContext *UNUSED(eval_ctx),
 	/* imat is needed for solvers. */
 	invert_m4_m4(ob->imat, ob->obmat);
 
-	/* 1. clear flags */
-	for (pchan = pose->chanbase.first; pchan != NULL; pchan = pchan->next) {
+	const int num_channels = BLI_listbase_count(&pose->chanbase);
+	pose->chan_array = MEM_malloc_arrayN(
+	        num_channels, sizeof(bPoseChannel*), "pose->chan_array");
+
+	/* clear flags */
+	int pchan_index = 0;
+	for (bPoseChannel *pchan = pose->chanbase.first; pchan != NULL; pchan = pchan->next) {
 		pchan->flag &= ~(POSE_DONE | POSE_CHAIN | POSE_IKTREE | POSE_IKSPLINE);
+		pose->chan_array[pchan_index++] = pchan;
 	}
 }
 
 void BKE_pose_eval_init_ik(EvaluationContext *UNUSED(eval_ctx),
                            Scene *scene,
-                           Object *ob,
-                           bPose *UNUSED(pose))
+                           Object *ob)
 {
 	DEG_debug_print_eval(__func__, ob->id.name, ob);
 	BLI_assert(ob->type == OB_ARMATURE);
@@ -587,11 +592,11 @@ void BKE_pose_eval_init_ik(EvaluationContext *UNUSED(eval_ctx),
 	if (arm->flag & ARM_RESTPOS) {
 		return;
 	}
-	/* 2a. construct the IK tree (standard IK) */
+	/* construct the IK tree (standard IK) */
 	BIK_initialize_tree(scene, ob, ctime);
-	/* 2b. construct the Spline IK trees
+	/* construct the Spline IK trees
 	 *  - this is not integrated as an IK plugin, since it should be able
-	 *	  to function in conjunction with standard IK
+	 *    to function in conjunction with standard IK
 	 */
 	BKE_pose_splineik_init_tree(scene, ob, ctime);
 }
@@ -599,8 +604,10 @@ void BKE_pose_eval_init_ik(EvaluationContext *UNUSED(eval_ctx),
 void BKE_pose_eval_bone(EvaluationContext *UNUSED(eval_ctx),
                         Scene *scene,
                         Object *ob,
-                        bPoseChannel *pchan)
+                        int pchan_index)
 {
+	BLI_assert(ob->pose != NULL);
+	bPoseChannel *pchan = ob->pose->chan_array[pchan_index];
 	DEG_debug_print_eval_subdata(
 	        __func__, ob->id.name, ob, "pchan", pchan->name, pchan);
 	BLI_assert(ob->type == OB_ARMATURE);
@@ -635,8 +642,10 @@ void BKE_pose_eval_bone(EvaluationContext *UNUSED(eval_ctx),
 void BKE_pose_constraints_evaluate(EvaluationContext *UNUSED(eval_ctx),
                                    Scene *scene,
                                    Object *ob,
-                                   bPoseChannel *pchan)
+                                   int pchan_index)
 {
+	BLI_assert(ob->pose != NULL);
+	bPoseChannel *pchan = ob->pose->chan_array[pchan_index];
 	DEG_debug_print_eval_subdata(
 	        __func__, ob->id.name, ob, "pchan", pchan->name, pchan);
 	bArmature *arm = (bArmature *)ob->data;
@@ -655,8 +664,11 @@ void BKE_pose_constraints_evaluate(EvaluationContext *UNUSED(eval_ctx),
 }
 
 void BKE_pose_bone_done(EvaluationContext *UNUSED(eval_ctx),
-                        bPoseChannel *pchan)
+                        struct Object *ob,
+                        int pchan_index)
 {
+	BLI_assert(ob->pose != NULL);
+	bPoseChannel *pchan = ob->pose->chan_array[pchan_index];
 	float imat[4][4];
 	DEG_debug_print_eval(__func__, pchan->name, pchan);
 	if (pchan->bone) {
@@ -668,8 +680,10 @@ void BKE_pose_bone_done(EvaluationContext *UNUSED(eval_ctx),
 void BKE_pose_iktree_evaluate(EvaluationContext *UNUSED(eval_ctx),
                               Scene *scene,
                               Object *ob,
-                              bPoseChannel *rootchan)
+                              int rootchan_index)
 {
+	BLI_assert(ob->pose != NULL);
+	bPoseChannel *rootchan = ob->pose->chan_array[rootchan_index];
 	DEG_debug_print_eval_subdata(
 	        __func__, ob->id.name, ob, "rootchan", rootchan->name, rootchan);
 	BLI_assert(ob->type == OB_ARMATURE);
@@ -684,9 +698,11 @@ void BKE_pose_iktree_evaluate(EvaluationContext *UNUSED(eval_ctx),
 void BKE_pose_splineik_evaluate(EvaluationContext *UNUSED(eval_ctx),
                                 Scene *scene,
                                 Object *ob,
-                                bPoseChannel *rootchan)
+                                int rootchan_index)
 
 {
+	BLI_assert(ob->pose != NULL);
+	bPoseChannel *rootchan = ob->pose->chan_array[rootchan_index];
 	DEG_debug_print_eval_subdata(
 	        __func__, ob->id.name, ob, "rootchan", rootchan->name, rootchan);
 	BLI_assert(ob->type == OB_ARMATURE);
@@ -700,17 +716,23 @@ void BKE_pose_splineik_evaluate(EvaluationContext *UNUSED(eval_ctx),
 
 void BKE_pose_eval_flush(EvaluationContext *UNUSED(eval_ctx),
                          Scene *scene,
-                         Object *ob,
-                         bPose *UNUSED(pose))
+                         Object *ob)
 {
+	bPose *pose = ob->pose;
+	BLI_assert(pose != NULL);
+
 	float ctime = BKE_scene_frame_get(scene); /* not accurate... */
 	DEG_debug_print_eval(__func__, ob->id.name, ob);
 	BLI_assert(ob->type == OB_ARMATURE);
 
-	/* 6. release the IK tree */
+	/* release the IK tree */
 	BIK_release_tree(scene, ob, ctime);
 
 	ob->recalc &= ~OB_RECALC_ALL;
+
+	BLI_assert(pose->chan_array != NULL);
+	MEM_freeN(pose->chan_array);
+	pose->chan_array = NULL;
 }
 
 void BKE_pose_eval_proxy_copy(EvaluationContext *UNUSED(eval_ctx), Object *ob)
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 7b51ddcce92..c35e49b801f 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -5076,6 +5076,7 @@ static void direct_link_pose(FileData *fd, bPose *pose)
 	link_list(fd, &pose->agroups);
 
 	pose->chanhash = NULL;
+	pose->chan_array = NULL;
 
 	for (pchan = pose->chanbase.first; pchan; pchan=pchan->next) {
 		pchan->bone = NULL;
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.h b/source/blender/depsgraph/intern/builder/deg_builder_nodes.h
index 9d47dc6bced..17d2a4ad558 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.h
+++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.h
@@ -132,7 +132,7 @@ struct DepsgraphNodeBuilder {
 	void build_object_data(Object *object);
 	void build_object_transform(Object *object);
 	void build_object_constraints(Object *object);
-	void build_pose_constraints(Object *object, bPoseChannel *pchan);
+	void build_pose_constraints(Object *object, bPoseChannel *pchan, int pchan_index);
 	void build_rigidbody(Scene *scene);
 	void build_particles(Object *object);
 	void build_cloth(Object *object);
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc
index 73bbbcfa0b3..0c7c3d13d93 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc
@@ -64,16 +64,24 @@ extern "C" {
 
 namespace DEG {
 
-void DepsgraphNodeBuilder::build_pose_constraints(Object *obje

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list