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

Some optimizations. Adding a callgrind script

Panagiotis Christopoulos Charitos 13 жил өмнө
parent
commit
53e70a205f

+ 12 - 1
CMakeLists.txt

@@ -74,13 +74,24 @@ MESSAGE("++ AnKi window backend: ${ANKI_WINDOW_BACKEND}")
 # Build type
 IF(CMAKE_BUILD_TYPE STREQUAL Debug)
 ELSE()
-	SET(FLAGS " -s -ffast-math -march=native ")
+	SET(FLAGS " -ffast-math -march=native ")
 
 	SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS}")
 	SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAGS}")
 	SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FLAGS}")
 ENDIF()
 
+# Strip
+OPTION(ANKI_STRIP "Srip the symbols from the executables" OFF)
+IF(ANKI_STRIP)
+	MESSAGE("++ Stipping: true")
+	SET(CMAKE_CXX_FLAGS " -s ")
+	SET(CMAKE_C_FLAGS " -s ")
+	SET(CMAKE_EXE_LINKER_FLAGS " -s ")
+ELSE()
+	MESSAGE("++ Stipping: false")
+ENDIF()
+
 #
 # Install
 #

+ 6 - 0
include/anki/gl/Texture.h

@@ -17,6 +17,9 @@ class Texture;
 /// @addtogroup gl
 /// @{
 
+/// The absolute limit of textures
+const U MAX_TEXTURES = 512;
+
 /// Contains a few hints on how to crate textures
 class TextureManager
 {
@@ -117,6 +120,9 @@ private:
 	/// Texture units
 	Vector<Unit> units;
 
+	/// XXX
+	Vector<I8> texIdToUnitId;
+
 	/// The active texture unit
 	I activeUnit;
 

+ 3 - 3
include/anki/math/Mat4.inl.h

@@ -148,13 +148,13 @@ inline Mat4::Mat4(const Vec3& transl, const Mat3& rot)
 // Vec3, Mat3, F32
 inline Mat4::Mat4(const Vec3& translate, const Mat3& rotate, const F32 scale)
 {
-	if(!isZero(scale - 1.0))
+	if(isZero(scale - 1.0))
 	{
-		setRotationPart(rotate * scale);
+		setRotationPart(rotate);
 	}
 	else
 	{
-		setRotationPart(rotate);
+		setRotationPart(rotate * scale);
 	}
 
 	setTranslationPart(translate);

+ 3 - 0
run_callgrind.sh

@@ -0,0 +1,3 @@
+valgrind --tool=callgrind --callgrind-out-file=callgrind.out.tmp --collect-jumps=yes --branch-sim=yes --cache-sim=yes --simulate-wb=yes --cacheuse=yes --simulate-hwpref=yes ./build/testapp/testapp
+
+# --I1=32768,2,64 --D1=32768,2,64 --LL=1048576,16,64

+ 15 - 3
src/gl/Texture.cpp

@@ -75,12 +75,18 @@ TextureUnits::TextureUnits()
 
 	activeUnit = -1;
 	choseUnitTimes = 0;
+
+	texIdToUnitId.resize(MAX_TEXTURES, -1);
 }
 
 //==============================================================================
 I TextureUnits::whichUnit(const Texture& tex)
 {
 	GLuint glid = tex.getGlId();
+
+#if 1
+	return texIdToUnitId[glid];
+#else
 	I i = units.size();
 
 	do
@@ -89,6 +95,7 @@ I TextureUnits::whichUnit(const Texture& tex)
 	} while(i >= 0 && glid != units[i].tex);
 
 	return i;
+#endif
 }
 
 //==============================================================================
@@ -108,11 +115,13 @@ U TextureUnits::choseUnit(const Texture& tex, Bool& allreadyBinded)
 	++choseUnitTimes;
 	I myTexUnit = whichUnit(tex);
 
+	const GLuint texid = tex.getGlId();
+
 	// Already binded => renew it
 	//
 	if(myTexUnit != -1)
 	{
-		ANKI_ASSERT(units[myTexUnit].tex == tex.getGlId());
+		ANKI_ASSERT(units[myTexUnit].tex == texid);
 		units[myTexUnit].born = choseUnitTimes;
 		allreadyBinded = true;
 		return myTexUnit;
@@ -126,8 +135,9 @@ U TextureUnits::choseUnit(const Texture& tex, Bool& allreadyBinded)
 	{
 		if(units[i].tex == 0)
 		{
-			units[i].tex = tex.getGlId();
+			units[i].tex = texid;
 			units[i].born = choseUnitTimes;
+			texIdToUnitId[texid] = i;
 			return i;
 		}
 	}
@@ -144,8 +154,10 @@ U TextureUnits::choseUnit(const Texture& tex, Bool& allreadyBinded)
 		}
 	}
 
-	units[older].tex = tex.getGlId();
+	texIdToUnitId[units[older].tex] = -1;
+	units[older].tex = texid;
 	units[older].born = choseUnitTimes;
+	texIdToUnitId[tex.getGlId()] = older;
 	return older;
 }
 

+ 1 - 4
src/renderer/Dbg.cpp

@@ -44,10 +44,7 @@ void Dbg::init(const Renderer::Initializer& initializer)
 //==============================================================================
 void Dbg::run()
 {
-	if(!enabled)
-	{
-		return;
-	}
+	ANKI_ASSERT(enabled);
 
 	Scene& scene = r->getScene();
 

+ 5 - 1
src/renderer/MainRenderer.cpp

@@ -98,7 +98,11 @@ void MainRenderer::initGl()
 void MainRenderer::render(Scene& scene)
 {
 	Renderer::render(scene);
-	dbg.run();
+
+	if(dbg.getEnabled())
+	{
+		dbg.run();
+	}
 
 	// Render the PPS FAI to the framebuffer
 	//

+ 2 - 2
src/renderer/Tiler.cpp

@@ -207,8 +207,6 @@ void Tiler::updateTiles(Camera& cam, const Texture& depthMap)
 
 	r->drawQuad();
 
-	waitUpdate4Planes();
-
 	//
 	// Read pixels from the min/max pass
 	//
@@ -222,6 +220,8 @@ void Tiler::updateTiles(Camera& cam, const Texture& depthMap)
 		GL_UNSIGNED_INT, pixels);
 #endif
 
+	waitUpdate4Planes();
+
 	// 
 	// Update and transform the 2 planes
 	// 

+ 6 - 0
src/script/renderer/MainRenderer.cpp

@@ -10,11 +10,17 @@ static Dbg& getDbg(MainRenderer* self)
 	return self->getDbg();
 }
 
+static Pps& getPps(MainRenderer* self)
+{
+	return self->getPps();
+}
+
 ANKI_SCRIPT_WRAP(MainRenderer)
 {
 	ANKI_LUA_CLASS_BEGIN(lb, MainRenderer)
 		ANKI_LUA_CONSTRUCTOR()
 		ANKI_LUA_FUNCTION_AS_METHOD("getDbg", &getDbg)
+		ANKI_LUA_FUNCTION_AS_METHOD("getPps", &getPps)
 	ANKI_LUA_CLASS_END()
 }
 

+ 4 - 2
testapp/Main.cpp

@@ -315,7 +315,7 @@ void mainLoop()
 
 		// Sleep
 		//
-#if 1
+#if 0
 		timer.stop();
 		if(timer.getElapsedTime() < AppSingleton::get().getTimerTick())
 		{
@@ -323,7 +323,7 @@ void mainLoop()
 				- timer.getElapsedTime());
 		}
 #else
-		if(MainRendererSingleton::get().getFramesCount() == 1000)
+		if(MainRendererSingleton::get().getFramesCount() == 100)
 		{
 			break;
 		}
@@ -400,6 +400,8 @@ void initSubsystems(int argc, char* argv[])
 
 	// Parallel jobs
 	ThreadPoolSingleton::get().init(4);
+
+	SceneSingleton::get().setAmbientColor(Vec3(0.3));
 }
 
 //==============================================================================