Skip to content

Commit 54da2c4

Browse files
committed
UBSAN fix
1 parent c8aa4ff commit 54da2c4

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

‎Jolt/Physics/PhysicsUpdateContext.h‎

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ class PhysicsUpdateContext : public NonCopyable
3939

4040
struct BodyPairQueue
4141
{
42-
alignas(JPH_CACHE_LINE_SIZE) atomic<uint32> mWriteIdx { 0 }; ///< Next index to write in mBodyPair array (need to add thread index * mMaxBodyPairsPerQueue and modulo mMaxBodyPairsPerQueue)
43-
alignas(JPH_CACHE_LINE_SIZE) atomic<uint32> mReadIdx { 0 }; ///< Next index to read in mBodyPair array (need to add thread index * mMaxBodyPairsPerQueue and modulo mMaxBodyPairsPerQueue)
42+
atomic<uint32> mWriteIdx { 0 }; ///< Next index to write in mBodyPair array (need to add thread index * mMaxBodyPairsPerQueue and modulo mMaxBodyPairsPerQueue)
43+
uint8 mPadding1[JPH_CACHE_LINE_SIZE - sizeof(atomic<uint32>)];///< Moved to own cache line to avoid conflicts with consumer jobs
44+
45+
atomic<uint32> mReadIdx { 0 }; ///< Next index to read in mBodyPair array (need to add thread index * mMaxBodyPairsPerQueue and modulo mMaxBodyPairsPerQueue)
46+
uint8 mPadding2[JPH_CACHE_LINE_SIZE - sizeof(atomic<uint32>)];///< Moved to own cache line to avoid conflicts with producer/consumer jobs
4447
};
4548

4649
using BodyPairQueues = StaticArray<BodyPairQueue, cMaxConcurrency>;
@@ -63,12 +66,23 @@ class PhysicsUpdateContext : public NonCopyable
6366

6467
uint32 mNumActiveBodiesAtStepStart; ///< Number of bodies that were active at the start of the physics update step. Only these bodies will receive gravity (they are the first N in the active body list).
6568

66-
alignas(JPH_CACHE_LINE_SIZE) atomic<uint32> mDetermineActiveConstraintReadIdx { 0 }; ///< Next constraint for determine active constraints (in separate cache line to avoid false sharing)
67-
alignas(JPH_CACHE_LINE_SIZE) atomic<uint32> mNumActiveConstraints { 0 }; ///< Number of constraints in the mActiveConstraints array (in separate cache line to avoid false sharing)
68-
alignas(JPH_CACHE_LINE_SIZE) atomic<uint32> mSetupVelocityConstraintsReadIdx { 0 }; ///< Next constraint for setting up velocity constraints (in separate cache line to avoid false sharing)
69-
alignas(JPH_CACHE_LINE_SIZE) atomic<uint32> mStepListenerReadIdx { 0 }; ///< Next step listener to call (in separate cache line to avoid false sharing)
70-
alignas(JPH_CACHE_LINE_SIZE) atomic<uint32> mApplyGravityReadIdx { 0 }; ///< Next body to apply gravity to (in separate cache line to avoid false sharing)
71-
alignas(JPH_CACHE_LINE_SIZE) atomic<uint32> mActiveBodyReadIdx { 0 }; ///< Index of fist active body that has not yet been processed by the broadphase (in separate cache line to avoid false sharing)
69+
atomic<uint32> mDetermineActiveConstraintReadIdx { 0 }; ///< Next constraint for determine active constraints
70+
uint8 mPadding1[JPH_CACHE_LINE_SIZE - sizeof(atomic<uint32>)];///< Padding to avoid sharing cache line with the next atomic
71+
72+
atomic<uint32> mNumActiveConstraints { 0 }; ///< Number of constraints in the mActiveConstraints array
73+
uint8 mPadding2[JPH_CACHE_LINE_SIZE - sizeof(atomic<uint32>)];///< Padding to avoid sharing cache line with the next atomic
74+
75+
atomic<uint32> mSetupVelocityConstraintsReadIdx { 0 }; ///< Next constraint for setting up velocity constraints
76+
uint8 mPadding3[JPH_CACHE_LINE_SIZE - sizeof(atomic<uint32>)];///< Padding to avoid sharing cache line with the next atomic
77+
78+
atomic<uint32> mStepListenerReadIdx { 0 }; ///< Next step listener to call
79+
uint8 mPadding4[JPH_CACHE_LINE_SIZE - sizeof(atomic<uint32>)];///< Padding to avoid sharing cache line with the next atomic
80+
81+
atomic<uint32> mApplyGravityReadIdx { 0 }; ///< Next body to apply gravity to
82+
uint8 mPadding5[JPH_CACHE_LINE_SIZE - sizeof(atomic<uint32>)];///< Padding to avoid sharing cache line with the next atomic
83+
84+
atomic<uint32> mActiveBodyReadIdx { 0 }; ///< Index of fist active body that has not yet been processed by the broadphase
85+
uint8 mPadding6[JPH_CACHE_LINE_SIZE - sizeof(atomic<uint32>)];///< Padding to avoid sharing cache line with the next atomic
7286

7387
BodyPairQueues mBodyPairQueues; ///< Queues in which to put body pairs that need to be tested by the narrowphase
7488

0 commit comments

Comments
 (0)