Pārlūkot izejas kodu

Config additions & adding a func to get the CPU cores count

Panagiotis Christopoulos Charitos 12 gadi atpakaļ
vecāks
revīzija
f8db6c5395

+ 52 - 21
include/anki/Config.h.cmake

@@ -5,33 +5,46 @@
 #define ANKI_VERSION_MAJOR ${ANKI_VERSION_MAJOR}
 #define ANKI_REVISION ${ANKI_REVISION}
 
-#define ANKI_MATH_SIMD_NONE 1
-#define ANKI_MATH_SIMD_SSE 2
-#define ANKI_MATH_SIMD_NEON 3
-#define ANKI_MATH_SIMD ANKI_MATH_SIMD_${ANKI_MATH_SIMD}
+#if defined(NDEBUG)
+#	define ANKI_DEBUG !NDEBUG
+#else
+#	define ANKI_DEBUG 1
+#endif
 
-#define ANKI_WINDOW_BACKEND_GLXX11 1
-#define ANKI_WINDOW_BACKEND_EGLX11 2
-#define ANKI_WINDOW_BACKEND_EGLFBDEV 3
-#define ANKI_WINDOW_BACKEND ANKI_WINDOW_BACKEND_${ANKI_WINDOW_BACKEND}
-#define ANKI_WINDOW_BACKEND_STR "ANKI_WINDOW_BACKEND_${ANKI_WINDOW_BACKEND}"
+#define ANKI_FILE __FILE__
+#define ANKI_FUNC __func__
 
-#define ANKI_GL_DESKTOP 1
-#define ANKI_GL_ES 2
-#if ANKI_WINDOW_BACKEND == ANKI_WINDOW_BACKEND_GLXX11
-#	define ANKI_GL ANKI_GL_DESKTOP
-#	define ANKI_GL_STR "ANKI_GL_DESKTOP"
+// Operating system
+#define ANKI_OS_LINUX 1 
+#define ANKI_OS_ANDROID 2
+#define ANKI_OS_APPLE 3
+#define ANKI_OS_APPLE_IOS 4
+#define ANKI_OS_WINDOWS 5
+
+#if defined( __WIN32__ ) || defined( _WIN32 )
+#	define ANKI_OS ANKI_OS_WINDOWS
+#elif defined( __APPLE_CC__)
+#	if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 40000 \
+	|| __IPHONE_OS_VERSION_MIN_REQUIRED >= 40000
+#		define ANKI_OS ANKI_OS_APPLE_IOS
+#	else
+#		define ANKI_OS ANKI_OS_APPLE
+#	endif
+#elif defined(__ANDROID__)
+#	define ANKI_OS ANKI_OS_ANDROID
 #else
-#	define ANKI_GL ANKI_GL_ES
-#	define ANKI_GL_STR "ANKI_GL_ES"
+#	define ANKI_OS ANKI_OS_LINUX
 #endif
 
-#if defined(NDEBUG)
-#	define ANKI_DEBUG !NDEBUG
+// POSIX system or not
+#if ANKI_OS == ANKI_OS_LINUX || ANKI_OS == ANKI_OS_ANDROID \
+	|| ANKI_OS == ANKI_OS_APPLE || ANKI_OS == ANKI_OS_APPLE_IOS
+#	define ANKI_POSIX 1
 #else
-#	define ANKI_DEBUG 1
+#	define ANKI_POSIX 0
 #endif
 
+// CPU architecture
 #define ANKI_CPU_ARCH_INTEL 1
 #define ANKI_CPU_ARCH_ARM 2
 
@@ -49,8 +62,26 @@
 #	error "Unsupported compiler"
 #endif
 
-#define ANKI_FILE __FILE__
-#define ANKI_FUNC __func__
+#define ANKI_MATH_SIMD_NONE 1
+#define ANKI_MATH_SIMD_SSE 2
+#define ANKI_MATH_SIMD_NEON 3
+#define ANKI_MATH_SIMD ANKI_MATH_SIMD_${ANKI_MATH_SIMD}
+
+#define ANKI_WINDOW_BACKEND_GLXX11 1
+#define ANKI_WINDOW_BACKEND_EGLX11 2
+#define ANKI_WINDOW_BACKEND_EGLFBDEV 3
+#define ANKI_WINDOW_BACKEND ANKI_WINDOW_BACKEND_${ANKI_WINDOW_BACKEND}
+#define ANKI_WINDOW_BACKEND_STR "ANKI_WINDOW_BACKEND_${ANKI_WINDOW_BACKEND}"
+
+#define ANKI_GL_DESKTOP 1
+#define ANKI_GL_ES 2
+#if ANKI_WINDOW_BACKEND == ANKI_WINDOW_BACKEND_GLXX11
+#	define ANKI_GL ANKI_GL_DESKTOP
+#	define ANKI_GL_STR "ANKI_GL_DESKTOP"
+#else
+#	define ANKI_GL ANKI_GL_ES
+#	define ANKI_GL_STR "ANKI_GL_ES"
+#endif
 
 #if defined(__GNUC__)
 #	define ANKI_LIKELY(x) __builtin_expect((x), 1)

+ 1 - 1
include/anki/util/DynamicArray.h

@@ -71,7 +71,7 @@ public:
 	}
 
 	/// Copy is not permited
-	DynamicArray& operator=(const Foo&) = delete;
+	DynamicArray& operator=(const DynamicArray&) = delete;
 
 	/// Move
 	DynamicArray& operator=(DynamicArray&& other)

+ 21 - 0
include/anki/util/System.h

@@ -0,0 +1,21 @@
+#ifndef ANKI_UTIL_SYSTEM_H
+#define ANKI_UTIL_SYSTEM_H
+
+#include "anki/util/StdTypes.h"
+
+namespace anki {
+
+/// @addtogroup util
+/// @{
+/// @addtogroup system
+/// @{
+
+/// Get the number of CPU cores
+extern U32 getCpuCoresCount();
+
+/// @}
+/// @}
+
+} // end namespace anki
+
+#endif

+ 31 - 0
include/anki/util/Util.h

@@ -0,0 +1,31 @@
+#ifndef ANKI_UTIL_UTIL_H
+#define ANKI_UTIL_UTIL_H
+
+#include "anki/util/Allocator.h"
+#include "anki/util/Array.h"
+#include "anki/util/Assert.h"
+#include "anki/util/Barrier.h"
+#include "anki/util/BinaryStream.h"
+#include "anki/util/Bitset.h"
+#include "anki/util/ConstCharPtrHashMap.h"
+#include "anki/util/DynamicArray.h"
+#include "anki/util/Exception.h"
+#include "anki/util/Filesystem.h"
+#include "anki/util/Functions.h"
+#include "anki/util/HighRezTimer.h"
+#include "anki/util/LinuxMalinfo.h"
+#include "anki/util/Memory.h"
+#include "anki/util/NonCopyable.h"
+#include "anki/util/Object.h"
+#include "anki/util/Observer.h"
+#include "anki/util/Scanner.h"
+#include "anki/util/Singleton.h"
+#include "anki/util/StdTypes.h"
+#include "anki/util/StringList.h"
+#include "anki/util/System.h"
+#include "anki/util/Util.h"
+//#include "anki/util/Variant.h"
+#include "anki/util/Vector.h"
+#include "anki/util/Visitor.h"
+
+#endif

+ 2 - 0
src/core/App.cpp

@@ -2,6 +2,7 @@
 #include "anki/core/Logger.h"
 #include "anki/util/Exception.h"
 #include "anki/util/Filesystem.h"
+#include "anki/util/System.h"
 #include "anki/Config.h"
 #include <cstring>
 #include <sstream>
@@ -150,6 +151,7 @@ void App::printAppInfo()
 	msg << " " << ANKI_CPU_ARCH_STR;
 	msg << " " << ANKI_GL_STR;
 	msg << " " << ANKI_WINDOW_BACKEND_STR;
+	msg << " CPU cores " << getCpuCoresCount();
 
 	msg << " build date " __DATE__ ", " << "rev " << ANKI_REVISION;
 

+ 4 - 5
src/resource/MeshLoader.cpp

@@ -272,7 +272,11 @@ void MeshLoader::createVertTangents()
 		}
 		else
 		{
+			// Calc the det
 			det = 1.0 / det;
+
+			// Add a noise to the det to avoid zero tangents on mirrored cases
+			det *= ((rand() % 10) * getEpsilon<F32>());
 		}
 
 		Vec3 t = (edge02 * uvedge01.y() - edge01 * uvedge02.y()) * det;
@@ -298,11 +302,6 @@ void MeshLoader::createVertTangents()
 		t = t - n * n.dot(t);
 		t.normalize();
 
-		if(!isZero(t.getLength() - 1.0))
-		{
-			std::cout << "t " << std::endl;
-		}
-
 		b.normalize();
 
 		F32 w = ((n.cross(t)).dot(b) < 0.0) ? 1.0 : -1.0;

+ 1 - 1
src/util/CMakeLists.txt

@@ -1,4 +1,4 @@
-SET(ANKI_UTIL_SOURCES Assert.cpp BinaryStream.cpp Exception.cpp Functions.cpp StringList.cpp Filesystem.cpp Allocator.cpp Memory.cpp)
+SET(ANKI_UTIL_SOURCES Assert.cpp BinaryStream.cpp Exception.cpp Functions.cpp StringList.cpp Filesystem.cpp Allocator.cpp Memory.cpp System.cpp)
 
 IF(ANKI_PLATFORM STREQUAL "LINUX")
 	SET(ANKI_UTIL_SOURCES ${ANKI_UTIL_SOURCES} HighRezTimerPosix.cpp FilesystemPosix.cpp)

+ 22 - 0
src/util/System.cpp

@@ -0,0 +1,22 @@
+#include "anki/util/System.h"
+#include "anki/Config.h"
+
+#if ANKI_POSIX
+#	include <unistd.h>
+#else
+#	error "Unimplemented"
+#endif
+
+namespace anki {
+
+//==============================================================================
+U32 getCpuCoresCount()
+{
+#if ANKI_POSIX
+	return sysconf(_SC_NPROCESSORS_ONLN);
+#else
+#	error "Unimplemented"
+#endif
+}
+
+} // end namespace anki

+ 2 - 4
testapp/Main.cpp

@@ -18,8 +18,7 @@
 #include "anki/core/StdinListener.h"
 #include "anki/resource/Model.h"
 #include "anki/core/Logger.h"
-#include "anki/util/Filesystem.h"
-#include "anki/util/HighRezTimer.h"
+#include "anki/util/Util.h"
 #include "anki/resource/Skin.h"
 #include "anki/event/EventManager.h"
 #include "anki/event/MainRendererPpsHdrEvent.h"
@@ -28,7 +27,6 @@
 #include "anki/core/ThreadPool.h"
 #include "anki/core/Timestamp.h"
 #include "anki/core/NativeWindow.h"
-#include "anki/util/Functions.h"
 #include "anki/scene/Scene.h"
 #include "anki/event/LightEvent.h"
 #include "anki/event/MovableEvent.h"
@@ -562,7 +560,7 @@ void initSubsystems(int argc, char* argv[])
 	StdinListenerSingleton::get().start();
 
 	// Parallel jobs
-	ThreadPoolSingleton::get().init(8);
+	ThreadPoolSingleton::get().init(getCpuCoresCount());
 }
 
 //==============================================================================