2
0
Эх сурвалжийг харах

Fix UBSAN build (tests weren't failing on error) (#206)

Jorrit Rouwe 3 жил өмнө
parent
commit
a191a7740b

+ 2 - 2
Build/CMakeLists.txt

@@ -56,7 +56,7 @@ if (("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" OR "${CMAKE_SYSTEM_NAME}" STREQUA
 	set(CMAKE_CXX_FLAGS_RELEASE "/GS- /GL /Gy /O2 /Oi /Ot")
 	set(CMAKE_CXX_FLAGS_RELEASE "/GS- /GL /Gy /O2 /Oi /Ot")
 	set(CMAKE_CXX_FLAGS_DISTRIBUTION "/GS- /GL /Gy /O2 /Oi /Ot")
 	set(CMAKE_CXX_FLAGS_DISTRIBUTION "/GS- /GL /Gy /O2 /Oi /Ot")
 	set(CMAKE_CXX_FLAGS_RELEASEASAN "-fsanitize=address /Od")
 	set(CMAKE_CXX_FLAGS_RELEASEASAN "-fsanitize=address /Od")
-	set(CMAKE_CXX_FLAGS_RELEASEUBSAN "-fsanitize=undefined,implicit-conversion")
+	set(CMAKE_CXX_FLAGS_RELEASEUBSAN "-fsanitize=undefined,implicit-conversion -fno-sanitize-recover=all")
 	set(CMAKE_CXX_FLAGS_RELEASECOVERAGE "-fprofile-instr-generate -fcoverage-mapping")
 	set(CMAKE_CXX_FLAGS_RELEASECOVERAGE "-fprofile-instr-generate -fcoverage-mapping")
 
 
 	# Set linker flags
 	# Set linker flags
@@ -179,7 +179,7 @@ elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" OR "${CMAKE_SYSTEM_NAME}" STREQU
 	set(CMAKE_CXX_FLAGS_RELEASE "-O3")
 	set(CMAKE_CXX_FLAGS_RELEASE "-O3")
 	set(CMAKE_CXX_FLAGS_DISTRIBUTION "-O3")
 	set(CMAKE_CXX_FLAGS_DISTRIBUTION "-O3")
 	set(CMAKE_CXX_FLAGS_RELEASEASAN "-fsanitize=address")
 	set(CMAKE_CXX_FLAGS_RELEASEASAN "-fsanitize=address")
-	set(CMAKE_CXX_FLAGS_RELEASEUBSAN "-fsanitize=undefined,implicit-conversion")
+	set(CMAKE_CXX_FLAGS_RELEASEUBSAN "-fsanitize=undefined,implicit-conversion -fno-sanitize-recover=all")
 	set(CMAKE_CXX_FLAGS_RELEASECOVERAGE "-fprofile-instr-generate -fcoverage-mapping")
 	set(CMAKE_CXX_FLAGS_RELEASECOVERAGE "-fprofile-instr-generate -fcoverage-mapping")
 
 
 	# Set linker flags
 	# Set linker flags

+ 19 - 11
Jolt/Physics/PhysicsUpdateContext.h

@@ -81,8 +81,11 @@ public:
 
 
 	struct BodyPairQueue
 	struct BodyPairQueue
 	{
 	{
-		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) (moved to own cache line to avoid conflicts with consumer jobs)
-		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) (moved to own cache line to avoid conflicts with producer/consumer jobs)
+		atomic<uint32>		mWriteIdx { 0 };										///< Next index to write in mBodyPair array (need to add thread index * mMaxBodyPairsPerQueue and modulo mMaxBodyPairsPerQueue)
+		uint8				mPadding1[JPH_CACHE_LINE_SIZE - sizeof(atomic<uint32>)];///< Moved to own cache line to avoid conflicts with consumer jobs
+
+		atomic<uint32>		mReadIdx { 0 };											///< Next index to read in mBodyPair array (need to add thread index * mMaxBodyPairsPerQueue and modulo mMaxBodyPairsPerQueue)
+		uint8				mPadding2[JPH_CACHE_LINE_SIZE - sizeof(atomic<uint32>)];///< Moved to own cache line to avoid conflicts with producer/consumer jobs
 	};
 	};
 
 
 	using BodyPairQueues = StaticArray<BodyPairQueue, cMaxConcurrency>;
 	using BodyPairQueues = StaticArray<BodyPairQueue, cMaxConcurrency>;
@@ -102,15 +105,20 @@ public:
 
 
 		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).
 		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).
 
 
-		alignas(JPH_CACHE_LINE_SIZE) atomic<uint32>	mConstraintReadIdx { 0 };		///< Next constraint for determine active constraints (moved to own cache line since its modified frequently by different jobs)
-
-		alignas(JPH_CACHE_LINE_SIZE) atomic<uint32>	mNumActiveConstraints { 0 };	///< Number of constraints in the mActiveConstraints array
-
-		alignas(JPH_CACHE_LINE_SIZE) atomic<uint32>	mStepListenerReadIdx { 0 };		///< Next step listener to call (moved to own cache line since its modified frequently by different jobs)
-
-		alignas(JPH_CACHE_LINE_SIZE) atomic<uint32>	mApplyGravityReadIdx { 0 };		///< Next body to apply gravity to (moved to own cache line since its modified frequently by different jobs)
-
-		alignas(JPH_CACHE_LINE_SIZE) atomic<uint32>	mActiveBodyReadIdx { 0 };		///< Index of fist active body that has not yet been processed by the broadphase
+		atomic<uint32>		mConstraintReadIdx { 0 };								///< Next constraint for determine active constraints
+		uint8				mPadding1[JPH_CACHE_LINE_SIZE - sizeof(atomic<uint32>)];///< Padding to avoid sharing cache line with the next atomic
+		
+		atomic<uint32>		mNumActiveConstraints { 0 };							///< Number of constraints in the mActiveConstraints array
+		uint8				mPadding2[JPH_CACHE_LINE_SIZE - sizeof(atomic<uint32>)];///< Padding to avoid sharing cache line with the next atomic
+		
+		atomic<uint32>		mStepListenerReadIdx { 0 };								///< Next step listener to call
+		uint8				mPadding3[JPH_CACHE_LINE_SIZE - sizeof(atomic<uint32>)];///< Padding to avoid sharing cache line with the next atomic
+		
+		atomic<uint32>		mApplyGravityReadIdx { 0 };								///< Next body to apply gravity to
+		uint8				mPadding4[JPH_CACHE_LINE_SIZE - sizeof(atomic<uint32>)];///< Padding to avoid sharing cache line with the next atomic
+
+		atomic<uint32>		mActiveBodyReadIdx { 0 };								///< Index of fist active body that has not yet been processed by the broadphase
+		uint8				mPadding5[JPH_CACHE_LINE_SIZE - sizeof(atomic<uint32>)];///< Padding to avoid sharing cache line with the next atomic
 
 
 		BodyPairQueues		mBodyPairQueues;										///< Queues in which to put body pairs that need to be tested by the narrowphase
 		BodyPairQueues		mBodyPairQueues;										///< Queues in which to put body pairs that need to be tested by the narrowphase
 
 

+ 2 - 2
UnitTests/Core/InsertionSortTest.cpp

@@ -47,10 +47,10 @@ TEST_SUITE("InsertionSortTest")
 	{
 	{
 		UnitTestRandom random;
 		UnitTestRandom random;
 
 
-		Array<int> array;
+		Array<UnitTestRandom::result_type> array;
 		for (int i = 0; i < 100; i++)
 		for (int i = 0; i < 100; i++)
 		{
 		{
-			int value = random();
+			UnitTestRandom::result_type value = random();
 
 
 			// Insert value at beginning
 			// Insert value at beginning
 			array.insert(array.begin(), value);
 			array.insert(array.begin(), value);

+ 2 - 2
UnitTests/Core/QuickSortTest.cpp

@@ -47,10 +47,10 @@ TEST_SUITE("QuickSortTest")
 	{
 	{
 		UnitTestRandom random;
 		UnitTestRandom random;
 
 
-		Array<int> array;
+		Array<UnitTestRandom::result_type> array;
 		for (int i = 0; i < 1000; i++)
 		for (int i = 0; i < 1000; i++)
 		{
 		{
-			int value = random();
+			UnitTestRandom::result_type value = random();
 
 
 			// Insert value at beginning
 			// Insert value at beginning
 			array.insert(array.begin(), value);
 			array.insert(array.begin(), value);