[Bf-blender-cvs] [9226719] hair_system: Make hair debug functions threadsafe by passing explicit per-thread debug data to them, instead of using static global data.
Lukas Tönne
noreply at git.blender.org
Fri Aug 8 11:53:14 CEST 2014
Commit: 9226719ef50071fe9c899e6ffbff10372a3ab067
Author: Lukas Tönne
Date: Fri Aug 8 10:42:29 2014 +0200
Branches: hair_system
https://developer.blender.org/rB9226719ef50071fe9c899e6ffbff10372a3ab067
Make hair debug functions threadsafe by passing explicit per-thread
debug data to them, instead of using static global data.
===================================================================
M source/blender/hair/HAIR_capi.cpp
M source/blender/hair/intern/HAIR_debug.cpp
M source/blender/hair/intern/HAIR_debug.h
M source/blender/hair/intern/HAIR_solver.cpp
M source/blender/hair/intern/HAIR_solver.h
===================================================================
diff --git a/source/blender/hair/HAIR_capi.cpp b/source/blender/hair/HAIR_capi.cpp
index 7a6add5..81186ca 100644
--- a/source/blender/hair/HAIR_capi.cpp
+++ b/source/blender/hair/HAIR_capi.cpp
@@ -113,39 +113,52 @@ void HAIR_solver_step_debug(struct HAIR_Solver *csolver, float time, float times
Solver *solver = (Solver *)csolver;
Transform itfm(ob_imat);
- Debug::Points dbg_points;
- Debug::set_points(&dbg_points);
- Debug::CollisionContacts dbg_contacts;
- Debug::set_collision_contacts(&dbg_contacts);
+ DebugThreadDataVector thread_data_list;
+ solver->step_threaded(time, timestep, &thread_data_list);
- solver->step_threaded(time, timestep);
-
- Debug::set_points(NULL);
if (points && totpoints) {
int tot = solver->data()->totpoints;
*totpoints = tot;
*points = (HAIR_SolverDebugPoint *)MEM_mallocN(sizeof(HAIR_SolverDebugPoint) * tot, "hair solver point debug data");
- for (int i = 0; i < dbg_points.size(); ++i) {
- const Debug::Point &dbg_point = dbg_points[i];
- if (dbg_point.index < 0 || dbg_point.index >= tot)
- continue;
-
- HAIR_SolverDebugPoint *p = (*points) + dbg_point.index;
- copy_v3_v3(p->bend, transform_direction(itfm, dbg_point.bend).data());
- copy_v3_v3(p->frame[0], transform_direction(itfm, dbg_point.frame.normal).data());
- copy_v3_v3(p->frame[1], transform_direction(itfm, dbg_point.frame.tangent).data());
- copy_v3_v3(p->frame[2], transform_direction(itfm, dbg_point.frame.cotangent).data());
- }
}
- Debug::set_collision_contacts(NULL);
+ HAIR_SolverDebugContact *contact;
if (contacts && totcontacts) {
- *totcontacts = dbg_contacts.size();
- *contacts = (HAIR_SolverDebugContact *)MEM_mallocN(sizeof(HAIR_SolverDebugContact) * dbg_contacts.size(), "hair solver contact debug data");
- for (int i = 0; i < dbg_contacts.size(); ++i) {
- HAIR_SolverDebugContact *c = (*contacts) + i;
- copy_v3_v3(c->coA, transform_point(itfm, dbg_contacts[i].coA).data());
- copy_v3_v3(c->coB, transform_point(itfm, dbg_contacts[i].coB).data());
+ *totcontacts = 0;
+ for (int d = 0; d < thread_data_list.size(); ++d) {
+ const DebugThreadData &data = thread_data_list[d];
+ *totcontacts += data.contacts.size();
+ }
+ *contacts = (HAIR_SolverDebugContact *)MEM_mallocN(sizeof(HAIR_SolverDebugContact) * (*totcontacts), "hair solver contact debug data");
+ contact = *contacts;
+ }
+ else
+ contact = NULL;
+
+ for (int d = 0; d < thread_data_list.size(); ++d) {
+ const DebugThreadData &data = thread_data_list[d];
+
+ if (points && totpoints) {
+ int tot = solver->data()->totpoints;
+ for (int i = 0; i < data.points.size(); ++i) {
+ const DebugPoint &dbg_point = data.points[i];
+ if (dbg_point.index < 0 || dbg_point.index >= tot)
+ continue;
+
+ HAIR_SolverDebugPoint *p = (*points) + dbg_point.index;
+ copy_v3_v3(p->bend, transform_direction(itfm, dbg_point.bend).data());
+ copy_v3_v3(p->frame[0], transform_direction(itfm, dbg_point.frame.normal).data());
+ copy_v3_v3(p->frame[1], transform_direction(itfm, dbg_point.frame.tangent).data());
+ copy_v3_v3(p->frame[2], transform_direction(itfm, dbg_point.frame.cotangent).data());
+ }
+ }
+
+ if (contacts && totcontacts) {
+ for (int i = 0; i < data.contacts.size(); ++i, ++contact) {
+ HAIR_SolverDebugContact *c = contact;
+ copy_v3_v3(c->coA, transform_point(itfm, data.contacts[i].coA).data());
+ copy_v3_v3(c->coB, transform_point(itfm, data.contacts[i].coB).data());
+ }
}
}
}
diff --git a/source/blender/hair/intern/HAIR_debug.cpp b/source/blender/hair/intern/HAIR_debug.cpp
index 5ef391c..a2a5e34 100644
--- a/source/blender/hair/intern/HAIR_debug.cpp
+++ b/source/blender/hair/intern/HAIR_debug.cpp
@@ -32,9 +32,6 @@ HAIR_NAMESPACE_BEGIN
#ifdef HAIR_DEBUG
-Debug::CollisionContacts *Debug::m_contacts = NULL;
-Debug::Points *Debug::m_points = NULL;
-
#endif
diff --git a/source/blender/hair/intern/HAIR_debug.h b/source/blender/hair/intern/HAIR_debug.h
index 21b3f56..e9769e9 100644
--- a/source/blender/hair/intern/HAIR_debug.h
+++ b/source/blender/hair/intern/HAIR_debug.h
@@ -40,77 +40,61 @@ HAIR_NAMESPACE_BEGIN
struct SolverData;
-struct Debug {
- struct Point {
- int index;
-
- float3 bend;
- Frame frame;
- };
-
- typedef std::vector<Point> Points;
+struct DebugPoint {
+ int index;
- struct Contact {
- float3 coA, coB;
- };
+ float3 bend;
+ Frame frame;
+};
+
+struct DebugContact {
+ float3 coA, coB;
+};
+
+struct DebugThreadData
+{
+ typedef std::vector<DebugPoint> Points;
+ typedef std::vector<DebugContact> CollisionContacts;
- typedef std::vector<Contact> CollisionContacts;
+ CollisionContacts contacts;
+ Points points;
+};
+
+struct Debug {
- static void point(int index, const float3 &bend, const Frame &frame)
+ static void point(DebugThreadData *data, int index, const float3 &bend, const Frame &frame)
{
#ifdef HAIR_DEBUG
- if (m_points) {
- Point p;
+ if (data) {
+ DebugPoint p;
p.index = index;
p.bend = bend;
p.frame = frame;
- m_points->push_back(p);
+ data->points.push_back(p);
}
#else
+ (void)data;
+ (void)index;
(void)bend;
+ (void)frame;
#endif
}
- static void set_points(Points *points)
- {
-#ifdef HAIR_DEBUG
- m_points = points;
-#else
- (void)points;
-#endif
- }
-
- static void collision_contact(const float3 &coA, const float3 &coB)
+ static void collision_contact(DebugThreadData *data, const float3 &coA, const float3 &coB)
{
#ifdef HAIR_DEBUG
- if (m_contacts) {
- Contact c;
+ if (data) {
+ DebugContact c;
c.coA = coA;
c.coB = coB;
- m_contacts->push_back(c);
+ data->contacts.push_back(c);
}
#else
+ (void)data;
(void)coA;
(void)coB;
#endif
}
-
- static void set_collision_contacts(CollisionContacts *contacts)
- {
-#ifdef HAIR_DEBUG
- m_contacts = contacts;
-#else
- (void)contacts;
-#endif
- }
-
-#ifdef HAIR_DEBUG
-
-private:
- static CollisionContacts *m_contacts;
- static Points *m_points;
-
-#endif
};
HAIR_NAMESPACE_END
diff --git a/source/blender/hair/intern/HAIR_solver.cpp b/source/blender/hair/intern/HAIR_solver.cpp
index d0e85bc..4349480 100644
--- a/source/blender/hair/intern/HAIR_solver.cpp
+++ b/source/blender/hair/intern/HAIR_solver.cpp
@@ -455,7 +455,7 @@ static void advance_state(SolverData *data)
}
}
-void Solver::step_threaded(float time, float timestep)
+void Solver::step_threaded(float time, float timestep, DebugThreadDataVector *debug_thread_data)
{
typedef std::vector<SolverTaskData> SolverTaskVector;
diff --git a/source/blender/hair/intern/HAIR_solver.h b/source/blender/hair/intern/HAIR_solver.h
index 1f4c02b..24b7f41 100644
--- a/source/blender/hair/intern/HAIR_solver.h
+++ b/source/blender/hair/intern/HAIR_solver.h
@@ -43,6 +43,7 @@ struct rbGhostObject;
HAIR_NAMESPACE_BEGIN
+struct DebugThreadData;
struct SolverTaskData;
struct SolverData {
@@ -147,6 +148,7 @@ struct PointContactInfo {
};
typedef std::vector<PointContactInfo> PointContactCache;
+typedef std::vector<DebugThreadData> DebugThreadDataVector;
class Solver
{
@@ -167,7 +169,7 @@ public:
void do_integration(float time, float timestep, const SolverTaskData &data) const;
- void step_threaded(float time, float timestep);
+ void step_threaded(float time, float timestep, DebugThreadDataVector *debug_thread_data = NULL);
private:
HairParams m_params;
More information about the Bf-blender-cvs
mailing list