Browse Source

Fix MSVC build

Panagiotis Christopoulos Charitos 6 years ago
parent
commit
c20963b680

+ 15 - 35
CMakeLists.txt

@@ -1,4 +1,4 @@
-CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
+CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
 
 
 PROJECT(anki)
 PROJECT(anki)
 
 
@@ -135,10 +135,6 @@ endif()
 # Compiler & linker flags                                                      #
 # Compiler & linker flags                                                      #
 ################################################################################
 ################################################################################
 
 
-set(CXX_FLAGS "")
-set(COMPILER_FLAGS "")
-set(LINKER_FLAGS "")
-
 if(NOT MSVC)
 if(NOT MSVC)
 	if(ARCH_64)
 	if(ARCH_64)
 		add_definitions(-D_POSIX_VER_64)
 		add_definitions(-D_POSIX_VER_64)
@@ -160,61 +156,45 @@ add_definitions(-DIMGUI_USER_CONFIG=<anki/ui/ImGuiConfig.h>)
 
 
 if(NOT MSVC)
 if(NOT MSVC)
 	# When building AnKi define this special flag
 	# When building AnKi define this special flag
-	set(COMPILER_FLAGS "${COMPILER_FLAGS} -fPIC ")
-
-	if(NOT ANKI_CPU_ADDR_SPACE STREQUAL "0")
-		set(LINKER_FLAGS "${LINKER_FLAGS} -m${ANKI_CPU_ADDR_SPACE} ")
-		set(COMPILER_FLAGS "${COMPILER_FLAGS} -m${ANKI_CPU_ADDR_SPACE} ")
-	endif()
+	add_definitions("-fPIC")
 
 
-	set(COMPILER_FLAGS "${COMPILER_FLAGS} -fno-exceptions ")
+	add_definitions("-fno-exceptions")
 
 
 	if(GCC AND NOT CLANG)
 	if(GCC AND NOT CLANG)
-		set(CXX_FLAGS "${CXX_FLAGS} -static-libstdc++ ")
+		add_definitions("-static-libstdc++")
 	endif()
 	endif()
 
 
 	if(LINUX OR MACOS OR WINDOWS)
 	if(LINUX OR MACOS OR WINDOWS)
-		set(COMPILER_FLAGS "${COMPILER_FLAGS} -msse4 ")
+		add_definitions("-msse4")
 	else()
 	else()
-		set(COMPILER_FLAGS "${COMPILER_FLAGS} -mfpu=neon ")
+		add_definitions("-mfpu=neon")
 	endif()
 	endif()
 
 
 	if(ANKI_LTO)
 	if(ANKI_LTO)
-		set(COMPILER_FLAGS "${COMPILER_FLAGS} -flto ")
+		add_definitions("-flto ")
 		set(LINKER_FLAGS "${LINKER_FLAGS} -flto ")
 		set(LINKER_FLAGS "${LINKER_FLAGS} -flto ")
 	endif()
 	endif()
 
 
 	if(ANKI_STRIP)
 	if(ANKI_STRIP)
 		set(LINKER_FLAGS "${LINKER_FLAGS} -s ")
 		set(LINKER_FLAGS "${LINKER_FLAGS} -s ")
-		set(COMPILER_FLAGS "${COMPILER_FLAGS} -s ")
+		add_definitions("-s")
 	endif()
 	endif()
 
 
 	if(ANKI_ADDRESS_SANITIZER)
 	if(ANKI_ADDRESS_SANITIZER)
-		set(COMPILER_FLAGS "${COMPILER_FLAGS} -fsanitize=address ")
+		add_definitions("-fsanitize=address ")
 	endif()
 	endif()
 
 
 	if(${CMAKE_BUILD_TYPE} STREQUAL "Release")
 	if(${CMAKE_BUILD_TYPE} STREQUAL "Release")
-		set(COMPILER_FLAGS "${COMPILER_FLAGS} -O3 -DNDEBUG ")
-
-		set(CMAKE_CXX_FLAGS_RELEASE "")
-		set(CMAKE_C_FLAGS_RELEASE "")
+		add_definitions("-O3 -DNDEBUG")
 	elseif(${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo")
 	elseif(${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo")
-		set(COMPILER_FLAGS "${COMPILER_FLAGS} -O3 -g3 ")
-
-		set(CMAKE_CXX_FLAGS_RELWITHDBGINFO "")
-		set(CMAKE_C_FLAGS_RELWITHDBGINFO "")
+		add_definitions("-O3 -g3")
 	elseif(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
 	elseif(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
-		set(COMPILER_FLAGS "${COMPILER_FLAGS} -O0 -g3 ")
-
-		set(CMAKE_CXX_FLAGS_DEBUG "")
-		set(CMAKE_C_FLAGS_DEBUG "")
+		add_definitions("-O0 -g3")
 	else()
 	else()
 		message(FATAL_ERROR "Wrong CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
 		message(FATAL_ERROR "Wrong CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
 	endif()
 	endif()
 
 
 	# Set the flags to cmake now
 	# Set the flags to cmake now
-	set(CMAKE_CXX_FLAGS "${CXX_FLAGS} ${COMPILER_FLAGS}")
-	set(CMAKE_C_FLAGS "${COMPILER_FLAGS}")
 	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LINKER_FLAGS}")
 	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LINKER_FLAGS}")
 endif()
 endif()
 
 
@@ -379,9 +359,9 @@ endif()
 
 
 # AnKi compiler flags (Mainly warnings)
 # AnKi compiler flags (Mainly warnings)
 if(NOT MSVC)
 if(NOT MSVC)
-	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -W -Wextra -Wstrict-aliasing -Wwrite-strings -Wunused -Wunused-variable -Wno-unused-parameter -Wundef -Wno-ignored-attributes -Wno-implicit-fallthrough -Wunused-result -std=c++14")
+	add_definitions("-pedantic -Wall -W -Wextra -Wstrict-aliasing -Wwrite-strings -Wunused -Wunused-variable -Wno-unused-parameter -Wundef -Wno-ignored-attributes -Wno-implicit-fallthrough -Wunused-result -std=c++14")
 else()
 else()
-	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4996 /wd4244 /wd4262 /wd4267")
+	add_definitions("/wd4996 /wd4244 /wd4262 /wd4267")
 endif()
 endif()
 
 
 # Set platform specific
 # Set platform specific
@@ -413,7 +393,7 @@ elseif(WINDOWS)
 			message(FATAL_ERROR "You need to have VULKAN SDK installed and the VULKAN_SDK env variable set")
 			message(FATAL_ERROR "You need to have VULKAN SDK installed and the VULKAN_SDK env variable set")
 		endif()
 		endif()
 
 
-		link_directories($ENV{VULKAN_SDK}/Bin)
+		link_directories($ENV{VULKAN_SDK}/Lib)
 		set(THIRD_PARTY_LIBS vulkan-1)
 		set(THIRD_PARTY_LIBS vulkan-1)
 	endif()
 	endif()
 
 

+ 3 - 3
shaders/glsl_cpp_common/ClusteredShading.h

@@ -13,10 +13,10 @@ ANKI_BEGIN_NAMESPACE
 
 
 // Consts
 // Consts
 const U32 TYPED_OBJECT_COUNT = 5u;
 const U32 TYPED_OBJECT_COUNT = 5u;
-const F32 INVALID_TEXTURE_INDEX = -1.0;
-const F32 LIGHT_FRUSTUM_NEAR_PLANE = 0.1 / 4.0; // The near plane on the shadow map frustums.
+const F32 INVALID_TEXTURE_INDEX = -1.0f;
+const F32 LIGHT_FRUSTUM_NEAR_PLANE = 0.1f / 4.0f; // The near plane on the shadow map frustums.
 const U32 MAX_SHADOW_CASCADES = 4u;
 const U32 MAX_SHADOW_CASCADES = 4u;
-const F32 SUBSURFACE_MIN = 0.05;
+const F32 SUBSURFACE_MIN = 0.05f;
 
 
 // See the documentation in the ClustererBin class.
 // See the documentation in the ClustererBin class.
 struct ClustererMagicValues
 struct ClustererMagicValues

+ 4 - 4
src/anki/math/Mat.h

@@ -43,7 +43,7 @@ public:
 	}
 	}
 
 
 	/// Copy.
 	/// Copy.
-	TMat(ANKI_ENABLE_TYPE(const TMat&, !HAS_SIMD) b)
+	TMat(ANKI_ENABLE_ARG(const TMat&, !HAS_SIMD) b)
 	{
 	{
 		for(U i = 0; i < N; i++)
 		for(U i = 0; i < N; i++)
 		{
 		{
@@ -52,7 +52,7 @@ public:
 	}
 	}
 
 
 	/// Copy.
 	/// Copy.
-	TMat(ANKI_ENABLE_TYPE(const TMat&, HAS_SIMD) b)
+	TMat(ANKI_ENABLE_ARG(const TMat&, HAS_SIMD) b)
 	{
 	{
 		for(U i = 0; i < J; i++)
 		for(U i = 0; i < J; i++)
 		{
 		{
@@ -379,7 +379,7 @@ public:
 	/// @{
 	/// @{
 
 
 	/// Copy.
 	/// Copy.
-	TMat& operator=(ANKI_ENABLE_TYPE(const TMat&, !HAS_SIMD) b)
+	TMat& operator=(ANKI_ENABLE_ARG(const TMat&, !HAS_SIMD) b)
 	{
 	{
 		for(U n = 0; n < N; n++)
 		for(U n = 0; n < N; n++)
 		{
 		{
@@ -389,7 +389,7 @@ public:
 	}
 	}
 
 
 	/// Copy.
 	/// Copy.
-	TMat& operator=(ANKI_ENABLE_TYPE(const TMat&, HAS_SIMD) b)
+	TMat& operator=(ANKI_ENABLE_ARG(const TMat&, HAS_SIMD) b)
 	{
 	{
 		for(U i = 0; i < J; i++)
 		for(U i = 0; i < J; i++)
 		{
 		{

+ 4 - 4
src/anki/math/Vec.h

@@ -33,7 +33,7 @@ public:
 	}
 	}
 
 
 	// Copy
 	// Copy
-	TVec(ANKI_ENABLE_TYPE(const TVec&, !HAS_VEC4_SIMD) b)
+	TVec(ANKI_ENABLE_ARG(const TVec&, !HAS_VEC4_SIMD) b)
 	{
 	{
 		for(U i = 0; i < N; i++)
 		for(U i = 0; i < N; i++)
 		{
 		{
@@ -42,7 +42,7 @@ public:
 	}
 	}
 
 
 	// Copy
 	// Copy
-	TVec(ANKI_ENABLE_TYPE(const TVec&, HAS_VEC4_SIMD) b)
+	TVec(ANKI_ENABLE_ARG(const TVec&, HAS_VEC4_SIMD) b)
 	{
 	{
 		m_simd = b.m_simd;
 		m_simd = b.m_simd;
 	}
 	}
@@ -2297,7 +2297,7 @@ public:
 	/// @{
 	/// @{
 
 
 	// Copy
 	// Copy
-	TVec& operator=(ANKI_ENABLE_TYPE(const TVec&, !HAS_VEC4_SIMD) b)
+	TVec& operator=(ANKI_ENABLE_ARG(const TVec&, !HAS_VEC4_SIMD) b)
 	{
 	{
 		for(U i = 0; i < N; i++)
 		for(U i = 0; i < N; i++)
 		{
 		{
@@ -2307,7 +2307,7 @@ public:
 	}
 	}
 
 
 	// Copy
 	// Copy
-	TVec& operator=(ANKI_ENABLE_TYPE(const TVec&, HAS_VEC4_SIMD) b)
+	TVec& operator=(ANKI_ENABLE_ARG(const TVec&, HAS_VEC4_SIMD) b)
 	{
 	{
 		m_simd = b.m_simd;
 		m_simd = b.m_simd;
 		return *this;
 		return *this;

+ 2 - 1
src/anki/scene/Visibility.cpp

@@ -185,7 +185,8 @@ void GatherVisiblesFromOctreeTask::gather(ThreadHive& hive)
 	flush(hive);
 	flush(hive);
 
 
 	// Fire an additional dummy task to decrease the semaphore to zero
 	// Fire an additional dummy task to decrease the semaphore to zero
-	ThreadHiveTask task = ANKI_THREAD_HIVE_TASK({}, this, nullptr, m_frcCtx->m_visTestsSignalSem);
+	GatherVisiblesFromOctreeTask* pself = this; // MSVC workaround
+	ThreadHiveTask task = ANKI_THREAD_HIVE_TASK({}, pself, nullptr, m_frcCtx->m_visTestsSignalSem);
 	hive.submitTasks(&task, 1);
 	hive.submitTasks(&task, 1);
 }
 }
 
 

+ 6 - 2
src/anki/scene/components/LightComponent.h

@@ -5,9 +5,9 @@
 
 
 #pragma once
 #pragma once
 
 
-#include <anki/scene/components/SceneComponent.h>
-#include <anki/renderer/RenderQueue.h>
 #include <anki/Math.h>
 #include <anki/Math.h>
+#include <anki/renderer/RenderQueue.h>
+#include <anki/scene/components/SceneComponent.h>
 
 
 namespace anki
 namespace anki
 {
 {
@@ -31,6 +31,10 @@ public:
 
 
 	LightComponent(LightComponentType type, U64 uuid);
 	LightComponent(LightComponentType type, U64 uuid);
 
 
+	~LightComponent()
+	{
+	}
+
 	LightComponentType getLightComponentType() const
 	LightComponentType getLightComponentType() const
 	{
 	{
 		return m_type;
 		return m_type;

+ 46 - 13
src/anki/util/Functions.h

@@ -248,6 +248,48 @@ inline void splitThreadedProblem(
 /// Make a preprocessor token a string.
 /// Make a preprocessor token a string.
 #define ANKI_STRINGIZE(a) _ANKI_STRINGIZE(a)
 #define ANKI_STRINGIZE(a) _ANKI_STRINGIZE(a)
 
 
+// ANKI_ENABLE_METHOD & ANKI_ENABLE_ARG trickery copied from Tick library
+template<bool B>
+struct RequiresBool
+{
+	static constexpr bool VALUE = B;
+};
+
+template<typename T, int N>
+struct RequiresUnwrap : T
+{
+};
+
+template<int N>
+struct PrivateEnum
+{
+	enum class Type
+	{
+		NA
+	};
+};
+
+template<typename T, int N>
+struct DummyType
+{
+};
+
+#if defined(_MSC_VER)
+#	define ANKI_REQUIRES_BOOL(line, ...) RequiresUnwrap<decltype(RequiresBool<(__VA_ARGS__)>{}), line>::VALUE
+
+#	define ANKI_ENABLE_METHOD_INTERNAL(line, ...) \
+		typename PrivateEnum<line>::Type ANKI_CONCATENATE( \
+			TickPrivateEnum, line) = PrivateEnum<line>::Type::NA, \
+							 bool ANKI_CONCATENATE(privateBool, line) = true, \
+							 typename = typename std::enable_if_t<( \
+								 ANKI_CONCATENATE(privateBool, line) && ANKI_REQUIRES_BOOL(line, __VA_ARGS__))>
+#else
+
+#	define ANKI_ENABLE_METHOD_INTERNAL(line, ...) \
+		bool privateBool##line = true, typename std::enable_if_t<(privateBool##line && __VA_ARGS__), int> = 0
+
+#endif
+
 /// Use it to enable a method based on a constant expression.
 /// Use it to enable a method based on a constant expression.
 /// @code
 /// @code
 /// template<int N> class Foo {
 /// template<int N> class Foo {
@@ -255,24 +297,15 @@ inline void splitThreadedProblem(
 /// 	void foo() {}
 /// 	void foo() {}
 ///	};
 ///	};
 /// @endcode
 /// @endcode
-#define ANKI_ENABLE_METHOD(expression) \
-	template<bool dependOn = true, \
-		typename std::enable_if< \
-			(std::is_same<typename std::conditional<(expression) && dependOn, int, double>::type, int>::value), \
-			int>::type = 0>
-
-template<typename T, int LINE>
-struct DummyType
-{
-};
+#define ANKI_ENABLE_METHOD(...) template<ANKI_ENABLE_METHOD_INTERNAL(__LINE__, __VA_ARGS__)>
 
 
 /// Use it to enable a method based on a constant expression.
 /// Use it to enable a method based on a constant expression.
 /// @code
 /// @code
-/// template<int N> class Foo {
-/// 	void foo(ANKI_ENABLE_TYPE(Boo) b) {}
+/// class Foo {
+/// 	void foo(ANKI_ENABLE_ARG(Boo, expr) b) {}
 ///	};
 ///	};
 /// @endcode
 /// @endcode
-#define ANKI_ENABLE_TYPE(type_, expression) \
+#define ANKI_ENABLE_ARG(type_, expression) \
 	typename std::conditional<(expression), type_, DummyType<type_, __LINE__>>::type
 	typename std::conditional<(expression), type_, DummyType<type_, __LINE__>>::type
 /// @}
 /// @}
 
 

+ 1 - 1
thirdparty

@@ -1 +1 @@
-Subproject commit f4948663bdd9d14809db7d746184cf5ebd74caca
+Subproject commit 903a4e96a27bb0ba522d8e81634701f898d62736