Jorrit Rouwe 3 anni fa
parent
commit
ddf837d782

+ 22 - 2
.github/workflows/build.yml

@@ -15,9 +15,9 @@ on:
       - '**.txt'
 
 jobs:
-  linux:
+  linux-clang:
     runs-on: ubuntu-latest
-    name: Linux
+    name: Linux Clang
     strategy:
         fail-fast: false
         matrix:
@@ -35,6 +35,26 @@ jobs:
       working-directory: ${{github.workspace}}/Build/Linux_${{matrix.build_type}}_${{matrix.clang_version}}
       run: ctest --output-on-failure
 
+  linux-gcc:
+    runs-on: ubuntu-latest
+    name: Linux GCC
+    strategy:
+        fail-fast: false
+        matrix:
+            build_type: [Debug, Release, Distribution]
+            clang_version: [g++]
+
+    steps:
+    - name: Checkout Code
+      uses: actions/checkout@v2
+    - name: Configure CMake
+      run: cmake -B ${{github.workspace}}/Build/Linux_${{matrix.build_type}}_${{matrix.clang_version}} -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_CXX_COMPILER=${{matrix.clang_version}} Build
+    - name: Build
+      run: cmake --build ${{github.workspace}}/Build/Linux_${{matrix.build_type}}_${{matrix.clang_version}} --config ${{matrix.build_type}}
+    - name: Test
+      working-directory: ${{github.workspace}}/Build/Linux_${{matrix.build_type}}_${{matrix.clang_version}}
+      run: ctest --output-on-failure
+
   msvc_cl:
     runs-on: windows-latest
     name: Visual Studio CL

+ 1 - 1
.github/workflows/sonar-cloud.yml

@@ -49,7 +49,7 @@ jobs:
       - name: Configure CMake
         run: |
             cd ${{github.workspace}}/Build/
-            ./cmake_linux_clang.sh ReleaseCoverage clang++-${{ env.CLANG_VERSION }}
+            ./cmake_linux_clang_gcc.sh ReleaseCoverage clang++-${{ env.CLANG_VERSION }}
       - name: Run build-wrapper
         run: |
           build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build ${{github.workspace}}/Build/Linux_ReleaseCoverage

+ 8 - 2
Build/CMakeLists.txt

@@ -47,10 +47,16 @@ elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
 	# Set general compiler flags (do not use -ffast-math since it cannot be turned off in a single compilation unit)
 	set(CMAKE_CXX_FLAGS "-g -std=c++17 -I. -Wall -Werror")
 
+	if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
+		# Somehow -Wcomment doesn't want to be turned off from code and we need this because Doxygen MathJax uses it
+		# Also turn off automatic fused multiply add contractions, there doesn't seem to be a way to do this selectively through the macro JPH_PRECISE_MATH_OFF
+		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-comment -ffp-contract=off")
+	endif()
+
 	# Platform specific compiler flags
 	if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64")
 		# X64
-		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx2 -mfma -mf16c -mlzcnt -mpopcnt")
+		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx2 -mfma -mf16c -mlzcnt -mbmi -mpopcnt")
 	elseif ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
 		# ARM64
 		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
@@ -65,7 +71,7 @@ elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
 	set(CMAKE_CXX_FLAGS_RELEASECOVERAGE "-DNDEBUG -fprofile-instr-generate -fcoverage-mapping")
 
 	# Set linker flags
-	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lpthread")
+	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread")
 endif()
 
 # Set linker flags

+ 1 - 1
Build/README.md

@@ -58,7 +58,7 @@ To override the default trace and assert mechanism install your own custom handl
 
 - Install clang (apt-get install clang)
 - Install cmake (apt-get install cmake)
-- Run: ./cmake_linux_clang.sh
+- Run: ./cmake_linux_clang_gcc.sh
 - Go to the Linux_Debug folder
 - Run: make -j 8 && ./UnitTests
 

+ 2 - 2
Build/cmake_linux_clang.sh → Build/cmake_linux_clang_gcc.sh

@@ -16,9 +16,9 @@ fi
 
 BUILD_DIR=Linux_$BUILD_TYPE
 
-echo Usage: ./cmake_linux_clang.sh [Configuration] [Compiler]
+echo Usage: ./cmake_linux_clang_gcc.sh [Configuration] [Compiler]
 echo "Possible configurations: Debug (default), Release, Distribution, ReleaseUBSAN, ReleaseASAN, ReleaseCoverage"
-echo "Possible compilers: clang++, clang++-XX where XX is the version"
+echo "Possible compilers: clang++, clang++-XX, g++, g++-XX where XX is the version"
 echo Generating Makefile for build type \"$BUILD_TYPE\" and compiler \"$COMPILER\" in folder \"$BUILD_DIR\"
 
 cmake -S . -B $BUILD_DIR -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_CXX_COMPILER=$COMPILER

+ 17 - 8
Jolt/Core/Core.h

@@ -48,6 +48,12 @@
 	#ifndef JPH_PLATFORM_ANDROID
 		#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
 	#endif
+#elif defined(__GNUC__)
+	#define JPH_COMPILER_GCC
+
+	#pragma GCC diagnostic ignored "-Wcomment"
+	#pragma GCC diagnostic ignored "-Winvalid-offsetof"
+	#pragma GCC diagnostic ignored "-Wclass-memaccess"
 #elif defined(_MSC_VER)
 	#define JPH_COMPILER_MSVC
 
@@ -84,17 +90,20 @@
 	#if (defined(__LZCNT__) || defined(__AVX2__)) && !defined(JPH_USE_LZCNT)
 		#define JPH_USE_LZCNT
 	#endif
+	#if (defined(__BMI__) || defined(__AVX2__)) && !defined(JPH_USE_TZCNT)
+		#define JPH_USE_TZCNT
+	#endif
 	#if defined(__AVX__) && !defined(JPH_USE_AVX)
 		#define JPH_USE_AVX
 	#endif
 	#if defined(__AVX2__) && !defined(JPH_USE_AVX2)
 		#define JPH_USE_AVX2
 	#endif
-	#if defined(__clang__)
+	#if defined(JPH_COMPILER_CLANG) || defined(JPH_COMPILER_GCC)
 		#if defined(__FMA__) && !defined(JPH_USE_FMADD)
 			#define JPH_USE_FMADD
 		#endif
-	#elif defined(_MSC_VER)
+	#elif defined(JPH_COMPILER_MSVC)
 		#if defined(__AVX2__) && !defined(JPH_USE_FMADD) // AVX2 also enables fused multiply add
 			#define JPH_USE_FMADD
 		#endif
@@ -168,9 +177,9 @@ static_assert(sizeof(uint64) == 8, "Invalid size of uint64");
 static_assert(sizeof(void *) == 8, "Invalid size of pointer");
 
 // Define inline macro
-#if defined(__clang__)
+#if defined(JPH_COMPILER_CLANG) || defined(JPH_COMPILER_GCC)
 	#define JPH_INLINE __inline__ __attribute__((always_inline))
-#elif defined(_MSC_VER)
+#elif defined(JPH_COMPILER_MSVC)
 	#define JPH_INLINE __forceinline
 #else
 	#error Undefined
@@ -182,9 +191,9 @@ static_assert(sizeof(void *) == 8, "Invalid size of pointer");
 #endif
 
 // Define macro to get current function name
-#if defined(__clang__)
+#if defined(JPH_COMPILER_CLANG) || defined(JPH_COMPILER_GCC)
 	#define JPH_FUNCTION_NAME	__PRETTY_FUNCTION__
-#elif defined(_MSC_VER)
+#elif defined(JPH_COMPILER_MSVC)
 	#define JPH_FUNCTION_NAME	__FUNCTION__
 #else
 	#error Undefined
@@ -204,14 +213,14 @@ static_assert(sizeof(void *) == 8, "Invalid size of pointer");
 #define JPH_UNUSED(x)			(void)x
 
 // Macro to enable floating point precise mode and to disable fused multiply add instructions
-#if defined(__clang__)
+#if defined(JPH_COMPILER_CLANG) || defined(JPH_COMPILER_GCC)
 	// In clang it appears you cannot turn off -ffast-math and -ffp-contract=fast for a code block
 	// There is #pragma clang fp contract (off) but that doesn't seem to work under clang 9 & 10 when -ffast-math is specified on the commandline (you override it to turn it on, but not off)
 	// There is #pragma float_control(precise, on) but that doesn't work under clang 9.
 	// So for now we compile clang without -ffast-math so the macros are empty
 	#define JPH_PRECISE_MATH_ON
 	#define JPH_PRECISE_MATH_OFF
-#elif defined(_MSC_VER)
+#elif defined(JPH_COMPILER_MSVC)
 	// Unfortunately there is no way to push the state of fp_contract, so we have to assume it was turned on before JPH_PRECISE_MATH_ON
 	#define JPH_PRECISE_MATH_ON						\
 		__pragma(float_control(precise, on, push))	\

+ 5 - 2
Jolt/Core/TickCounter.h

@@ -3,8 +3,11 @@
 
 #pragma once
 
-#ifdef JPH_PLATFORM_WINDOWS
-	#include <intrin.h> // for __rdtsc
+// Include for __rdtsc
+#if defined(JPH_PLATFORM_WINDOWS)
+	#include <intrin.h> 
+#elif defined(JPH_CPU_X64) && defined(JPH_COMPILER_GCC)
+	#include <x86intrin.h>
 #endif
 
 namespace JPH {

+ 2 - 2
Jolt/Math/Math.h

@@ -94,7 +94,7 @@ inline bool IsAligned(T inV, uint64 inAlignment)
 inline uint CountTrailingZeros(uint32 inValue)
 {
 #if defined(JPH_CPU_X64)
-	#if defined(JPH_USE_LZCNT)
+	#if defined(JPH_USE_TZCNT)
 		return _tzcnt_u32(inValue);
 	#elif defined(JPH_COMPILER_MSVC)
 		if (inValue == 0)
@@ -141,7 +141,7 @@ inline uint CountLeadingZeros(uint32 inValue)
 /// Count the number of 1 bits in a value
 inline uint CountBits(uint32 inValue)
 {
-#if defined(JPH_COMPILER_CLANG)
+#if defined(JPH_COMPILER_CLANG) || defined(JPH_COMPILER_GCC)
     return __builtin_popcount(inValue);
 #elif defined(JPH_COMPILER_MSVC)
 	return _mm_popcnt_u32(inValue);

+ 1 - 1
Jolt/Physics/Body/BodyManager.h

@@ -212,7 +212,7 @@ public:
 
 private:
 	/// Increment and get the sequence number of the body
-#ifdef __clang__
+#ifdef JPH_COMPILER_CLANG
 	__attribute__((no_sanitize("implicit-conversion"))) // We intentionally overflow the uint8 sequence number
 #endif
 	inline uint8					GetNextSequenceNumber(int inBodyIndex)		{ return ++mBodySequenceNumbers[inBodyIndex]; }

+ 4 - 0
PerformanceTest/PerformanceTest.cpp

@@ -52,7 +52,9 @@ int main(int argc, char** argv)
 	uint max_iterations = 500;
 	bool disable_sleep = false;
 	bool enable_profiler = false;
+#ifdef JPH_DEBUG_RENDERER
 	bool enable_debug_renderer = false;
+#endif // JPH_DEBUG_RENDERER
 	bool enable_per_frame_recording = false;
 	unique_ptr<PerformanceTestScene> scene;
 	for (int argidx = 1; argidx < argc; ++argidx)
@@ -103,10 +105,12 @@ int main(int argc, char** argv)
 		{
 			enable_profiler = true;
 		}
+	#ifdef JPH_DEBUG_RENDERER
 		else if (strcmp(arg, "-r") == 0)
 		{
 			enable_debug_renderer = true;
 		}
+	#endif // JPH_DEBUG_RENDERER
 		else if (strcmp(arg, "-f") == 0)
 		{
 			enable_per_frame_recording = true;

+ 1 - 1
README.md

@@ -87,7 +87,7 @@ For more information see the [Architecture and API documentation](https://jrouwe
 
 ## Compiling
 
-* The library has been tested to compile with Cl (Visual Studio) and Clang 10+.
+* The library has been tested to compile with Cl (Visual Studio 2019-2022), Clang 10+ and GCC 9+.
 * It uses C++17 and only depends on the standard template library.
 * It doesn't make use of compiler generated RTTI or exceptions.
 * If you want to run on Platform Blue you'll need to provide your own build environment and PlatformBlue.h file due to NDA requirements (see Core.h for further info).

+ 1 - 1
TestFramework/Input/Keyboard.cpp

@@ -44,7 +44,7 @@ void Keyboard::ResetKeyboard()
 }
 
 bool Keyboard::Initialize(Renderer *inRenderer) 
-#ifdef __clang__
+#ifdef JPH_COMPILER_CLANG
 	// DIPROP_BUFFERSIZE is a pointer to 1 which causes UBSan: runtime error: reference binding to misaligned address 0x000000000001
 	__attribute__((no_sanitize("alignment")))
 #endif

+ 1 - 1
TestFramework/Input/Mouse.cpp

@@ -42,7 +42,7 @@ void Mouse::ResetMouse()
 }
 
 bool Mouse::Initialize(Renderer *inRenderer)
-#ifdef __clang__
+#ifdef JPH_COMPILER_CLANG
 	// DIPROP_BUFFERSIZE is a pointer to 1 which causes UBSan: runtime error: reference binding to misaligned address 0x000000000001
 	__attribute__((no_sanitize("alignment")))
 #endif

+ 1 - 1
TestFramework/TestFramework.h

@@ -23,7 +23,7 @@
 #include <wrl.h> // for ComPtr
 #pragma warning (pop)
 
-#if defined(__clang__)
+#if defined(JPH_COMPILER_CLANG)
 	#pragma clang diagnostic ignored "-Wheader-hygiene"
 #endif
 

+ 1 - 0
UnitTests/UnitTestFramework.cpp

@@ -3,6 +3,7 @@
 
 #include <Jolt.h>
 
+#include <cstdarg>
 #include <Core/FPException.h>
 #include <RegisterTypes.h>
 #ifdef JPH_PLATFORM_ANDROID

+ 1 - 1
UnitTests/UnitTestFramework.h

@@ -6,7 +6,7 @@
 #include <Math/Float2.h>
 #include "doctest.h"
 
-#if defined(__clang__)
+#if defined(JPH_COMPILER_CLANG)
 	#pragma clang diagnostic ignored "-Wheader-hygiene"
 #endif