|
@@ -106,7 +106,7 @@ void SoftBodyMotionProperties::DetermineCollidingShapes(const SoftBodyUpdateCont
|
|
|
JPH_PROFILE_FUNCTION();
|
|
|
|
|
|
// Reset flag prior to collision detection
|
|
|
- mNeedContactCallback = false;
|
|
|
+ mNeedContactCallback.store(false, memory_order_relaxed);
|
|
|
|
|
|
struct Collector : public CollideShapeBodyCollector
|
|
|
{
|
|
@@ -236,6 +236,7 @@ void SoftBodyMotionProperties::DetermineCollidingShapes(const SoftBodyUpdateCont
|
|
|
DefaultBroadPhaseLayerFilter broadphase_layer_filter = inSystem.GetDefaultBroadPhaseLayerFilter(layer);
|
|
|
DefaultObjectLayerFilter object_layer_filter = inSystem.GetDefaultLayerFilter(layer);
|
|
|
inSystem.GetBroadPhaseQuery().CollideAABox(world_bounds, collector, broadphase_layer_filter, object_layer_filter);
|
|
|
+ mNumSensors = uint(mCollidingSensors.size()); // Workaround for TSAN false positive: store mCollidingSensors.size() in a separate variable.
|
|
|
}
|
|
|
|
|
|
void SoftBodyMotionProperties::DetermineCollisionPlanes(uint inVertexStart, uint inNumVertices)
|
|
@@ -269,7 +270,7 @@ void SoftBodyMotionProperties::DetermineSensorCollisions(CollidingSensor &ioSens
|
|
|
|
|
|
// We need a contact callback if one of the sensors collided
|
|
|
if (ioSensor.mHasContact)
|
|
|
- mNeedContactCallback = true;
|
|
|
+ mNeedContactCallback.store(true, memory_order_relaxed);
|
|
|
}
|
|
|
|
|
|
void SoftBodyMotionProperties::ApplyPressure(const SoftBodyUpdateContext &inContext)
|
|
@@ -621,7 +622,7 @@ void SoftBodyMotionProperties::ApplyCollisionConstraintsAndUpdateVelocities(cons
|
|
|
v.mHasContact = true;
|
|
|
|
|
|
// We need a contact callback if one of the vertices collided
|
|
|
- mNeedContactCallback = true;
|
|
|
+ mNeedContactCallback.store(true, memory_order_relaxed);
|
|
|
|
|
|
// Note that we already calculated the velocity, so this does not affect the velocity (next iteration starts by setting previous position to current position)
|
|
|
CollidingShape &cs = mCollidingShapes[v.mCollidingShapeIndex];
|
|
@@ -720,7 +721,7 @@ void SoftBodyMotionProperties::UpdateSoftBodyState(SoftBodyUpdateContext &ioCont
|
|
|
JPH_PROFILE_FUNCTION();
|
|
|
|
|
|
// Contact callback
|
|
|
- if (mNeedContactCallback && ioContext.mContactListener != nullptr)
|
|
|
+ if (mNeedContactCallback.load(memory_order_relaxed) && ioContext.mContactListener != nullptr)
|
|
|
{
|
|
|
// Remove non-colliding sensors from the list
|
|
|
for (int i = int(mCollidingSensors.size()) - 1; i >= 0; --i)
|
|
@@ -877,7 +878,7 @@ SoftBodyMotionProperties::EStatus SoftBodyMotionProperties::ParallelDetermineCol
|
|
|
// Process collision planes
|
|
|
uint num_vertices_to_process = min(SoftBodyUpdateContext::cVertexCollisionBatch, num_vertices - next_vertex);
|
|
|
DetermineCollisionPlanes(next_vertex, num_vertices_to_process);
|
|
|
- uint vertices_processed = ioContext.mNumCollisionVerticesProcessed.fetch_add(SoftBodyUpdateContext::cVertexCollisionBatch, memory_order_release) + num_vertices_to_process;
|
|
|
+ uint vertices_processed = ioContext.mNumCollisionVerticesProcessed.fetch_add(SoftBodyUpdateContext::cVertexCollisionBatch, memory_order_acq_rel) + num_vertices_to_process;
|
|
|
if (vertices_processed >= num_vertices)
|
|
|
{
|
|
|
// Determine next state
|
|
@@ -896,19 +897,18 @@ SoftBodyMotionProperties::EStatus SoftBodyMotionProperties::ParallelDetermineCol
|
|
|
SoftBodyMotionProperties::EStatus SoftBodyMotionProperties::ParallelDetermineSensorCollisions(SoftBodyUpdateContext &ioContext)
|
|
|
{
|
|
|
// Do a relaxed read to see if there are more sensors to process
|
|
|
- uint num_sensors = (uint)mCollidingSensors.size();
|
|
|
- if (ioContext.mNextSensorIndex.load(memory_order_relaxed) < num_sensors)
|
|
|
+ if (ioContext.mNextSensorIndex.load(memory_order_relaxed) < mNumSensors)
|
|
|
{
|
|
|
// Fetch next sensor to process
|
|
|
uint sensor_index = ioContext.mNextSensorIndex.fetch_add(1, memory_order_acquire);
|
|
|
- if (sensor_index < num_sensors)
|
|
|
+ if (sensor_index < mNumSensors)
|
|
|
{
|
|
|
// Process this sensor
|
|
|
DetermineSensorCollisions(mCollidingSensors[sensor_index]);
|
|
|
|
|
|
// Determine next state
|
|
|
- uint sensors_processed = ioContext.mNumSensorsProcessed.fetch_add(1, memory_order_release) + 1;
|
|
|
- if (sensors_processed >= num_sensors)
|
|
|
+ uint sensors_processed = ioContext.mNumSensorsProcessed.fetch_add(1, memory_order_acq_rel) + 1;
|
|
|
+ if (sensors_processed >= mNumSensors)
|
|
|
StartFirstIteration(ioContext);
|
|
|
return EStatus::DidWork;
|
|
|
}
|
|
@@ -961,7 +961,7 @@ SoftBodyMotionProperties::EStatus SoftBodyMotionProperties::ParallelApplyConstra
|
|
|
ProcessGroup(ioContext, next_group);
|
|
|
|
|
|
// Increment total number of groups processed
|
|
|
- num_groups_processed = ioContext.mNumConstraintGroupsProcessed.fetch_add(1, memory_order_relaxed) + 1;
|
|
|
+ num_groups_processed = ioContext.mNumConstraintGroupsProcessed.fetch_add(1, memory_order_acq_rel) + 1;
|
|
|
}
|
|
|
|
|
|
if (num_groups_processed >= num_groups)
|
|
@@ -981,7 +981,7 @@ SoftBodyMotionProperties::EStatus SoftBodyMotionProperties::ParallelApplyConstra
|
|
|
StartNextIteration(ioContext);
|
|
|
|
|
|
// Reset group logic
|
|
|
- ioContext.mNumConstraintGroupsProcessed.store(0, memory_order_relaxed);
|
|
|
+ ioContext.mNumConstraintGroupsProcessed.store(0, memory_order_release);
|
|
|
ioContext.mNextConstraintGroup.store(0, memory_order_release);
|
|
|
}
|
|
|
else
|
|
@@ -1002,7 +1002,7 @@ SoftBodyMotionProperties::EStatus SoftBodyMotionProperties::ParallelApplyConstra
|
|
|
|
|
|
SoftBodyMotionProperties::EStatus SoftBodyMotionProperties::ParallelUpdate(SoftBodyUpdateContext &ioContext, const PhysicsSettings &inPhysicsSettings)
|
|
|
{
|
|
|
- switch (ioContext.mState.load(memory_order_relaxed))
|
|
|
+ switch (ioContext.mState.load(memory_order_acquire))
|
|
|
{
|
|
|
case SoftBodyUpdateContext::EState::DetermineCollisionPlanes:
|
|
|
return ParallelDetermineCollisionPlanes(ioContext);
|