Răsfoiți Sursa

- Adding the initial stuf for benchmarking
- Writing unit tests for math lib
- Fixing a math lib bug (thanks to unit testing!!!!)

Panagiotis Christopoulos Charitos 15 ani în urmă
părinte
comite
02b1ca978c

+ 0 - 0
benches/Main.cpp


+ 14 - 0
benches/build/gen.cfg.py

@@ -0,0 +1,14 @@
+sourcePaths = walkDir("../../src")
+sourcePaths.extend(list(walkDir("../", True)))
+
+includePaths = ["./"]
+includePaths.extend(list(sourcePaths))
+includePaths.extend(["../../extern/include", "../../extern/include/bullet", "/usr/include/python2.6"])
+
+executableName = "anki-benches"
+
+compiler = "g++"
+
+compilerFlags = "-DDEBUG_ENABLED=0 -DPLATFORM_LINUX -DMATH_INTEL_SIMD -DREVISION=\\\"`svnversion -c ../..`\\\" -c -msse4 -pedantic-errors -pedantic -ansi -Wall -Wextra -W -Wno-long-long -pipe -s -O3 -mtune=core2 -ffast-math -fsingle-precision-constant"
+
+linkerFlags = "-rdynamic -pg -L../../extern/lib-x86-64-linux -Wl,-Bstatic -lBulletSoftBody -lBulletDynamics -lBulletCollision -lLinearMath -lGLEW -lGLU -Wl,-Bdynamic -lGL -ljpeg -lSDL -lpng -lpython2.6 -lboost_system -lboost_python -lboost_filesystem -lboost_thread -lgtest"

Fișier diff suprimat deoarece este prea mare
+ 0 - 1
build/debug/Makefile


+ 1 - 1
src/Core/App.cpp

@@ -217,7 +217,7 @@ void App::initRenderer()
 	initializer.pps.hdr.blurringIterationsNum = 2;
 	initializer.pps.hdr.exposure = 4.0;
 	initializer.pps.ssao.blurringIterationsNum = 2;
-	initializer.pps.ssao.enabled = true;
+	initializer.pps.ssao.enabled = false;
 	initializer.pps.ssao.renderingQuality = 0.5;
 	initializer.mainRendererQuality = 1.0;
 	MainRendererSingleton::getInstance().init(initializer);

+ 1 - 1
src/Math/Mat4.inl.h

@@ -438,7 +438,7 @@ inline Mat4 Mat4::operator/(float f) const
 inline Mat4 operator/(float f, const Mat4& m4)
 {
 	Mat4 out;
-	for(uint i = 0; i < 9; i++)
+	for(uint i = 0; i < 16; i++)
 	{
 		out[i] = f / m4[i];
 	}

+ 1 - 1
src/Renderer/MainRenderer.cpp

@@ -100,7 +100,7 @@ void MainRenderer::render(Camera& cam_)
 	glDisable(GL_DEPTH_TEST);
 	glDisable(GL_BLEND);
 	sProg->bind();
-	//sProg->findUniVar("rasterImage")->setTexture(pps->getSsao().getFai(), 0);
+	//sProg->findUniVar("rasterImage")->setTexture(ms.getNormalFai(), 0);
 	sProg->findUniVar("rasterImage")->setTexture(pps.getPostPassFai(), 0);
 	drawQuad();
 }

+ 52 - 28
src/Resources/Texture.cpp

@@ -46,6 +46,58 @@ void Texture::load(const char* filename)
 {
 	try
 	{
+		/// @todo delete this
+		if(std::string("textures/stone.001.diff.tga") == filename)
+		{
+			target = GL_TEXTURE_2D;
+			glGenTextures(1, &glId);
+			bind(LAST_TEX_UNIT);
+
+			setRepeat(true);
+			int internalFormat;
+			int format;
+			int type;
+			internalFormat = (compressionEnabled) ? GL_COMPRESSED_RGB : GL_RGB;
+			format = GL_RGBA;
+			type = GL_UNSIGNED_BYTE;
+
+			int w = 100, h = 100;
+			int level = 0;
+			//uint cols
+			while(1)
+			{
+				uint col = rand();
+				Vec<uint> buff(w * h, col);
+				glTexImage2D(target, level, internalFormat, w, h, 0, format, type, &buff[0]);
+				++level;
+				w /= 2;
+				h /= 2;
+				if(w == 0 || h == 0)
+				{
+					break;
+				}
+			}
+
+			setTexParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+			//setTexParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+			setTexParameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+			setTexParameter(GL_TEXTURE_MAX_ANISOTROPY_EXT, float(anisotropyLevel));
+
+
+			/*w = img.getWidth();
+			h = img.getHeight();
+			Vec<uchar> buff__(w * h * 3, 0x0F);
+			glTexSubImage2D(target, 0, 0, 0, w, h, format, type, &buff__[0]);
+
+			w = img.getWidth() / 2;
+			h = img.getHeight() / 2;
+			Vec<uchar> buff(w * h * 3, 0xFF);
+			glTexSubImage2D(target, 1, 0, 0, w, h, format, type, &buff[0]);*/
+			return;
+		}
+
+
+
 		target = GL_TEXTURE_2D;
 		if(isLoaded())
 		{
@@ -101,40 +153,12 @@ void Texture::load(const char* filename)
 				throw EXCEPTION("See file");
 		}
 
-		/*if(std::string("textures/stone.001.diff.tga") == filename)
-		{
-			Vec<uchar> buff(img.getWidth() * img.getHeight(), 0xFF);
-
-			glTexImage2D(target, 0, internalFormat, img.getWidth(), img.getHeight(), 0, format, type, &buff[0]);
-		}
-		else*/
-
 		glTexImage2D(target, 0, internalFormat, img.getWidth(), img.getHeight(), 0, format, type, &img.getData()[0]);
 		if(mipmappingEnabled)
 		{
 			glGenerateMipmap(target);
 		}
 
-		/// @todo delete this
-		if(std::string("textures/stone.001.diff.tga") == filename)
-		{
-			//setMipmapLevel(7);
-			//INFO(filename << " " << getBaseLevel() << " " << getMaxLevel() << " " << getWidth(1));
-
-			int w, h;
-
-			w = img.getWidth();
-			h = img.getHeight();
-			Vec<uchar> buff__(w * h * 3, 0x0F);
-			glTexSubImage2D(target, 0, 0, 0, w, h, format, type, &buff__[0]);
-
-			w = img.getWidth() / 2;
-			h = img.getHeight() / 2;
-			Vec<uchar> buff(w * h * 3, 0xFF);
-			glTexSubImage2D(target, 1, 0, 0, w, h, format, type, &buff[0]);
-		}
-
-
 		ON_GL_FAIL_THROW_EXCEPTION();
 	}
 	catch(std::exception& e)

+ 163 - 0
unit-tests/Math/MathCommon.ut.h

@@ -0,0 +1,163 @@
+#ifndef MATH_COMMON_UT_H
+#define MATH_COMMON_UT_H
+
+#include "Util.h"
+
+
+/// Get random float and not zero cause of the divs
+inline float randFloat()
+{
+	const float RANGE_MIN = -1.00123;
+	const float RANGE_MAX = 900.9990001;
+
+	float f;
+	while(true)
+	{
+		f = Util::randRange(RANGE_MIN, RANGE_MAX);
+		if(!isZero(f))
+		{
+			break;
+		}
+	}
+
+	return f;
+}
+
+
+//======================================================================================================================
+// testCommonContructors                                                                                               =
+//======================================================================================================================
+template<typename Type>
+void testCommonContructors()
+{
+	Type a, b;
+	float f;
+	float arr[sizeof(Type) / sizeof(float)];
+
+	f = randFloat();
+	for(uint i = 0; i < (sizeof(Type) / sizeof(float)); i++)
+	{
+		a[i] = f;
+		b[i] = randFloat();
+		arr[i] = b[i];
+	}
+
+	// float
+	EXPECT_EQ(Type(f), a);
+
+	// arr
+	EXPECT_EQ(Type(arr), b);
+
+	// Copy
+	EXPECT_EQ(Type(b), b);
+}
+
+
+//======================================================================================================================
+// Test operators                                                                                                      =
+//======================================================================================================================
+
+inline float addf(float a, float b)
+{
+	return a + b;
+}
+
+
+inline float subf(float a, float b)
+{
+	return a - b;
+}
+
+
+inline float mulf(float a, float b)
+{
+	return a * b;
+}
+
+
+inline float divf(float a, float b)
+{
+	return a / b;
+}
+
+
+template<
+	typename Type,
+	Type (Type::* op)(const Type&) const,
+	Type& (Type::* compoundAssignment)(const Type&),
+	float (* normalOp)(float, float)>
+void testOperators()
+{
+	Type a, b, c;
+
+	for(uint i = 0; i < (sizeof(Type) / sizeof(float)); i++)
+	{
+		a[i] = randFloat();
+		b[i] = randFloat();
+		c[i] = normalOp(a[i], b[i]);
+	}
+
+	EXPECT_EQ((a.*op)(b), c);
+
+	(a.*compoundAssignment)(b);
+
+	EXPECT_EQ(a, c);
+}
+
+
+template<
+	typename Type,
+	Type (Type::* op)(float) const,
+	Type& (Type::* compoundAssignment)(float),
+	Type (* opExtern)(float, const Type&),
+	float (* normalOp)(float, float)>
+void testOperatorsWithFloat()
+{
+	Type a, b, c;
+	float f = randFloat();
+
+	for(uint i = 0; i < (sizeof(Type) / sizeof(float)); i++)
+	{
+		a[i] = randFloat();
+		b[i] = normalOp(a[i], f);
+		c[i] = normalOp(f, a[i]);
+	}
+
+	EXPECT_EQ((a.*op)(f), b);
+
+	EXPECT_EQ(opExtern(f, a), c);
+
+	(a.*compoundAssignment)(f);
+	EXPECT_EQ(a, b);
+}
+
+
+template<typename Type>
+void testCmpOperators()
+{
+	Type a, b;
+
+	for(uint i = 0; i < (sizeof(Type) / sizeof(float)); i++)
+	{
+		a[i] = b[i] = randFloat();
+	}
+
+	EXPECT_EQ(a == b, true);
+	EXPECT_EQ(a != b, false);
+}
+
+
+template<typename Type>
+void testNegOperator()
+{
+	Type a, b;
+	for(int i = 0; i < (sizeof(Type) / sizeof(float)); i++)
+	{
+		a[i] = randFloat();
+		b[i] = -a[i];
+	}
+
+	EXPECT_EQ(-a == b, true);
+}
+
+#endif

+ 24 - 0
unit-tests/Math/Matrices.ut.cpp

@@ -0,0 +1,24 @@
+#include <gtest/gtest.h>
+#include <iostream>
+#include "Math.h"
+#include "MathCommon.ut.h"
+
+
+template<typename Type>
+void arithmeticOperations()
+{
+	/*testOperators<Type, &Type::operator+, &Type::operator+=, &addf>();
+	testOperators<Type, &Type::operator-, &Type::operator-=, &subf>();
+	testOperatorsWithFloat<Type, &Type::operator+, &Type::operator+=, &operator+, &addf>();
+	testOperatorsWithFloat<Type, &Type::operator-, &Type::operator-=, &operator-, &subf>();
+	testOperatorsWithFloat<Type, &Type::operator*, &Type::operator*=, &operator*, &mulf>();*/
+	testOperatorsWithFloat<Type, &Type::operator/, &Type::operator/=, &operator/, &divf>();
+	/*testCmpOperators<Type>();*/
+}
+
+
+TEST(MathTests, MatrixOperators)
+{
+	arithmeticOperations<Mat3>();
+	arithmeticOperations<Mat4>();
+}

+ 7 - 156
unit-tests/Math/Math.ut.cpp → unit-tests/Math/Vectors.ut.cpp

@@ -1,28 +1,12 @@
 #include <gtest/gtest.h>
 #include <iostream>
 #include "Math.h"
-#include "Util.h"
+#include "MathCommon.ut.h"
 
 
-const float RANGE_MIN = -1.00123;
-const float RANGE_MAX = 900.9990001;
 const float REALY_SMALL_FLOAT = 1.0e-3;
 
-/// Get random float and not zero cause of the divs
-static float randFloat()
-{
-	float f;
-	while(true)
-	{
-		f = Util::randRange(RANGE_MIN, RANGE_MAX);
-		if(!isZero(f))
-		{
-			break;
-		}
-	}
 
-	return f;
-}
 
 
 //======================================================================================================================
@@ -42,155 +26,18 @@ TEST(MathTests, Alignment)
 }
 
 
-//======================================================================================================================
-// Constructors                                                                                                        =
-//======================================================================================================================
-
-template<typename Type>
-void testCommonContructors()
-{
-	Type a, b;
-	float f;
-	float arr[sizeof(Type) / sizeof(float)];
-
-	f = randFloat();
-	for(uint i = 0; i < (sizeof(Type) / sizeof(float)); i++)
-	{
-		a[i] = f;
-		b[i] =  randFloat();
-		arr[i] = b[i];
-	}
-
-	// float
-	EXPECT_EQ(Type(f), a);
-
-	// arr
-	EXPECT_EQ(Type(arr), b);
-
-	// Type
-	EXPECT_EQ(Type(b), b);
-}
-
-
-TEST(MathTests, Constructors)
+TEST(MathTests, VectorConstructors)
 {
 	testCommonContructors<Vec2>();
-
 	testCommonContructors<Vec3>();
-
-	// Vec4
 	testCommonContructors<Vec4>();
 }
 
 
 //======================================================================================================================
-// Arithmetic                                                                                                          =
+// Operators                                                                                                           =
 //======================================================================================================================
 
-float addf(float a, float b)
-{
-	return a + b;
-}
-
-
-float subf(float a, float b)
-{
-	return a - b;
-}
-
-
-float mulf(float a, float b)
-{
-	return a * b;
-}
-
-
-float divf(float a, float b)
-{
-	return a / b;
-}
-
-
-template<
-	typename Type,
-	Type (Type::* op)(const Type&) const,
-	Type& (Type::* compoundAssignment)(const Type&),
-	float (* normalOp)(float, float)>
-void testOperators()
-{
-	Type a, b, c;
-
-	for(uint i = 0; i < (sizeof(Type) / sizeof(float)); i++)
-	{
-		a[i] = randFloat();
-		b[i] = randFloat();
-		c[i] = normalOp(a[i], b[i]);
-	}
-
-	EXPECT_EQ((a.*op)(b), c);
-
-	(a.*compoundAssignment)(b);
-
-	EXPECT_EQ(a, c);
-}
-
-
-template<
-	typename Type,
-	Type (Type::* op)(float) const,
-	Type& (Type::* compoundAssignment)(float),
-	Type (* opExtern)(float, const Type&),
-	float (* normalOp)(float, float)>
-void testOperatorsWithFloat()
-{
-	Type a, b, c;
-	float f = randFloat();
-
-	for(uint i = 0; i < (sizeof(Type) / sizeof(float)); i++)
-	{
-		a[i] = randFloat();
-		b[i] = normalOp(a[i], f);
-		c[i] = normalOp(f, a[i]);
-	}
-
-	EXPECT_EQ((a.*op)(f), b);
-
-	EXPECT_EQ(opExtern(f, a), c);
-
-	(a.*compoundAssignment)(f);
-	EXPECT_EQ(a, b);
-}
-
-
-template<typename Type>
-void testCmpOperators()
-{
-	Type a, b;
-
-	for(uint i = 0; i < (sizeof(Type) / sizeof(float)); i++)
-	{
-		a[i] = b[i] = randFloat();
-	}
-
-	EXPECT_EQ(a == b, true);
-	EXPECT_EQ(a != b, false);
-}
-
-
-template<typename Type>
-void testNegOperator()
-{
-	Type a, b;
-	for(int i = 0; i < (sizeof(Type) / sizeof(float)); i++)
-	{
-		a[i] = randFloat();
-		b[i] = -a[i];
-	}
-
-	EXPECT_EQ(-a == b, true);
-}
-
-
 template<typename Type>
 void arithmeticOperations()
 {
@@ -214,6 +61,10 @@ TEST(MathTests, VectorArithmetic)
 }
 
 
+//======================================================================================================================
+// Misc                                                                                                                =
+//======================================================================================================================
+
 template<typename Type>
 void testDotProd()
 {

Fișier diff suprimat deoarece este prea mare
+ 0 - 1
unit-tests/build/Makefile


Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff