[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58279] branches/soc-2013-depsgraph_mt/ source/blender: Made armatures evaluation safe(r) for threading

Sergey Sharybin sergey.vfx at gmail.com
Mon Jul 15 20:46:19 CEST 2013


Revision: 58279
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58279
Author:   nazgul
Date:     2013-07-15 18:46:19 +0000 (Mon, 15 Jul 2013)
Log Message:
-----------
Made armatures evaluation safe(r) for threading

Apparently, some routines in armature deformation code
were using static arrays. This is probably just an
optimization thing, but it's very bad for threading.

Now made it so bbone matrices array is allocating in
callee function stack. This required exposing
MAX_BBONE_SUBDIV to an external API, This is not so
much crappy from code side, and it shall be the same
fast as before.

Modified Paths:
--------------
    branches/soc-2013-depsgraph_mt/source/blender/blenkernel/BKE_armature.h
    branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/armature.c
    branches/soc-2013-depsgraph_mt/source/blender/editors/armature/armature_skinning.c
    branches/soc-2013-depsgraph_mt/source/blender/editors/space_view3d/drawarmature.c

Modified: branches/soc-2013-depsgraph_mt/source/blender/blenkernel/BKE_armature.h
===================================================================
--- branches/soc-2013-depsgraph_mt/source/blender/blenkernel/BKE_armature.h	2013-07-15 18:46:15 UTC (rev 58278)
+++ branches/soc-2013-depsgraph_mt/source/blender/blenkernel/BKE_armature.h	2013-07-15 18:46:19 UTC (rev 58279)
@@ -124,11 +124,13 @@
 void BKE_rotMode_change_values(float quat[4], float eul[3], float axis[3], float *angle, short oldMode, short newMode);
 
 /* B-Bone support */
+#define MAX_BBONE_SUBDIV    32
+
 typedef struct Mat4 {
 	float mat[4][4];
 } Mat4;
 
-Mat4 *b_bone_spline_setup(struct bPoseChannel *pchan, int rest);
+void b_bone_spline_setup(struct bPoseChannel *pchan, int rest, Mat4 result_array[MAX_BBONE_SUBDIV]);
 
 /* like EBONE_VISIBLE */
 #define PBONE_VISIBLE(arm, bone) ( \

Modified: branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/armature.c
===================================================================
--- branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/armature.c	2013-07-15 18:46:15 UTC (rev 58278)
+++ branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/armature.c	2013-07-15 18:46:19 UTC (rev 58279)
@@ -381,8 +381,6 @@
 
 /* ************* B-Bone support ******************* */
 
-#define MAX_BBONE_SUBDIV    32
-
 /* data has MAX_BBONE_SUBDIV+1 interpolated points, will become desired amount with equal distances */
 static void equalize_bezier(float *data, int desired)
 {
@@ -426,11 +424,8 @@
 
 /* returns pointer to static array, filled with desired amount of bone->segments elements */
 /* this calculation is done  within unit bone space */
-Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest)
+void b_bone_spline_setup(bPoseChannel *pchan, int rest, Mat4 result_array[MAX_BBONE_SUBDIV])
 {
-	static Mat4 bbone_array[MAX_BBONE_SUBDIV];
-	static Mat4 bbone_rest_array[MAX_BBONE_SUBDIV];
-	Mat4 *result_array = (rest) ? bbone_rest_array : bbone_array;
 	bPoseChannel *next, *prev;
 	Bone *bone = pchan->bone;
 	float h1[3], h2[3], scale[3], length, hlength1, hlength2, roll1 = 0.0f, roll2;
@@ -587,8 +582,6 @@
 			mul_serie_m4(result_array[a].mat, iscalemat, result_array[a].mat, scalemat, NULL, NULL, NULL, NULL, NULL);
 		}
 	}
-
-	return result_array;
 }
 
 /* ************ Armature Deform ******************* */
@@ -602,13 +595,15 @@
 static void pchan_b_bone_defmats(bPoseChannel *pchan, bPoseChanDeform *pdef_info, int use_quaternion)
 {
 	Bone *bone = pchan->bone;
-	Mat4 *b_bone = b_bone_spline_setup(pchan, 0);
-	Mat4 *b_bone_rest = b_bone_spline_setup(pchan, 1);
+	Mat4 b_bone[MAX_BBONE_SUBDIV], b_bone_rest[MAX_BBONE_SUBDIV];
 	Mat4 *b_bone_mats;
 	DualQuat *b_bone_dual_quats = NULL;
 	float tmat[4][4] = MAT4_UNITY;
 	int a;
 
+	b_bone_spline_setup(pchan, 0, b_bone);
+	b_bone_spline_setup(pchan, 1, b_bone_rest);
+
 	/* allocate b_bone matrices and dual quats */
 	b_bone_mats = MEM_mallocN((1 + bone->segments) * sizeof(Mat4), "BBone defmats");
 	pdef_info->b_bone_mats = b_bone_mats;

Modified: branches/soc-2013-depsgraph_mt/source/blender/editors/armature/armature_skinning.c
===================================================================
--- branches/soc-2013-depsgraph_mt/source/blender/editors/armature/armature_skinning.c	2013-07-15 18:46:15 UTC (rev 58278)
+++ branches/soc-2013-depsgraph_mt/source/blender/editors/armature/armature_skinning.c	2013-07-15 18:46:19 UTC (rev 58279)
@@ -255,7 +255,7 @@
 	bDeformGroup *dgroup;
 	bPoseChannel *pchan;
 	Mesh *mesh;
-	Mat4 *bbone = NULL;
+	Mat4 bbone_array[MAX_BBONE_SUBDIV], *bbone = NULL;
 	float (*root)[3], (*tip)[3], (*verts)[3];
 	int *selected;
 	int numbones, vertsfilled = 0, i, j, segments = 0;
@@ -309,7 +309,8 @@
 				if ((par->pose) && (pchan = BKE_pose_channel_find_name(par->pose, bone->name))) {
 					if (bone->segments > 1) {
 						segments = bone->segments;
-						bbone = b_bone_spline_setup(pchan, 1);
+						b_bone_spline_setup(pchan, 1, bbone_array);
+						bbone = bbone_array;
 					}
 				}
 			}

Modified: branches/soc-2013-depsgraph_mt/source/blender/editors/space_view3d/drawarmature.c
===================================================================
--- branches/soc-2013-depsgraph_mt/source/blender/editors/space_view3d/drawarmature.c	2013-07-15 18:46:15 UTC (rev 58278)
+++ branches/soc-2013-depsgraph_mt/source/blender/editors/space_view3d/drawarmature.c	2013-07-15 18:46:19 UTC (rev 58279)
@@ -34,6 +34,7 @@
 #include <string.h>
 #include <math.h>
 
+#include "MEM_guardedalloc.h"
 
 #include "DNA_anim_types.h"
 #include "DNA_armature_types.h"
@@ -1109,12 +1110,14 @@
 	
 	if ((segments > 1) && (pchan)) {
 		float dlen = length / (float)segments;
-		Mat4 *bbone = b_bone_spline_setup(pchan, 0);
+		Mat4 bbone[MAX_BBONE_SUBDIV];
 		int a;
-		
-		for (a = 0; a < segments; a++, bbone++) {
+
+		b_bone_spline_setup(pchan, 0, bbone);
+
+		for (a = 0; a < segments; a++) {
 			glPushMatrix();
-			glMultMatrixf(bbone->mat);
+			glMultMatrixf(bbone[a].mat);
 			if (dt == OB_SOLID) drawsolidcube_size(xwidth, dlen, zwidth);
 			else drawcube_size(xwidth, dlen, zwidth);
 			glPopMatrix();
@@ -1245,6 +1248,7 @@
 static void draw_wire_bone(const short dt, int armflag, int boneflag, short constflag, unsigned int id,
                            bPoseChannel *pchan, EditBone *ebone)
 {
+	Mat4 bbones_array[MAX_BBONE_SUBDIV];
 	Mat4 *bbones = NULL;
 	int segments = 0;
 	float length;
@@ -1253,8 +1257,10 @@
 		segments = pchan->bone->segments;
 		length = pchan->bone->length;
 		
-		if (segments > 1)
-			bbones = b_bone_spline_setup(pchan, 0);
+		if (segments > 1) {
+			b_bone_spline_setup(pchan, 0, bbones_array);
+			bbones = bbones_array;
+		}
 	}
 	else 
 		length = ebone->length;




More information about the Bf-blender-cvs mailing list