Browse Source

Minor changes

Panagiotis Christopoulos Charitos 3 years ago
parent
commit
adfb457ca0
4 changed files with 55 additions and 16 deletions
  1. 17 3
      AnKi/Core/App.cpp
  2. 6 0
      AnKi/Util/HighRezTimer.h
  3. 13 5
      AnKi/Util/HighRezTimerPosix.cpp
  4. 19 8
      AnKi/Util/HighRezTimerWindows.cpp

+ 17 - 3
AnKi/Core/App.cpp

@@ -498,7 +498,7 @@ Error App::mainLoop()
 
 			// Render
 			TexturePtr presentableTex = m_gr->acquireNextPresentableTexture();
-			m_renderer->setStatsEnabled(m_config->getCoreDisplayStats() > 0
+			m_renderer->setStatsEnabled(m_config->getCoreDisplayStats() > 0 || benchmarkMode
 #if ANKI_ENABLE_TRACE
 										|| TracerSingleton::get().getEnabled()
 #endif
@@ -508,7 +508,21 @@ Error App::mainLoop()
 			// Pause and sync async loader. That will force all tasks before the pause to finish in this frame.
 			m_resources->getAsyncLoader().pause();
 
+			// If we get stats exclude the time of GR because it forces some GPU-CPU serialization. We don't want to
+			// count that
+			Second grTime = 0.0;
+			if(ANKI_UNLIKELY(benchmarkMode || m_config->getCoreDisplayStats() > 0))
+			{
+				grTime = HighRezTimer::getCurrentTime();
+			}
+
 			m_gr->swapBuffers();
+
+			if(ANKI_UNLIKELY(benchmarkMode || m_config->getCoreDisplayStats() > 0))
+			{
+				grTime = HighRezTimer::getCurrentTime() - grTime;
+			}
+
 			m_stagingMem->endFrame();
 			m_unifiedGometryMemPool->endFrame();
 			m_gpuSceneMemPool->endFrame();
@@ -536,7 +550,7 @@ Error App::mainLoop()
 			// Benchmark stats
 			else
 			{
-				aggregatedCpuTime += frameTime;
+				aggregatedCpuTime += frameTime - grTime;
 				aggregatedGpuTime += m_renderer->getStats().m_renderingGpuTime;
 				++benchmarkFramesGathered;
 				if(benchmarkFramesGathered >= kBenchmarkFramesToGatherBeforeFlush)
@@ -555,7 +569,7 @@ Error App::mainLoop()
 			if(m_config->getCoreDisplayStats() > 0)
 			{
 				StatsUiInput in;
-				in.m_cpuFrameTime = frameTime;
+				in.m_cpuFrameTime = frameTime - grTime;
 				in.m_rendererTime = m_renderer->getStats().m_renderingCpuTime;
 				in.m_sceneUpdateTime = m_scene->getStats().m_updateTime;
 				in.m_visibilityTestsTime = m_scene->getStats().m_visibilityTestsTime;

+ 6 - 0
AnKi/Util/HighRezTimer.h

@@ -28,6 +28,12 @@ public:
 	/// Get the current date's seconds
 	static Second getCurrentTime();
 
+	/// Get the current date's mili seconds
+	static U64 getCurrentTimeMs();
+
+	/// Get the current date's micro seconds
+	static U64 getCurrentTimeUs();
+
 	/// Micro sleep. The resolution is in nanoseconds.
 	static void sleep(Second seconds);
 

+ 13 - 5
AnKi/Util/HighRezTimerPosix.cpp

@@ -27,7 +27,7 @@ public:
 	}
 };
 
-StartTime startTime;
+static StartTime g_startTime;
 
 } // namespace
 
@@ -37,8 +37,7 @@ static U64 getNs()
 
 	timespec now;
 	clock_gettime(CLOCK_MONOTONIC, &now);
-	ticks =
-		static_cast<U64>(now.tv_sec - startTime.m_time.tv_sec) * 1000000000 + (now.tv_nsec - startTime.m_time.tv_nsec);
+	ticks = U64(now.tv_sec - g_startTime.m_time.tv_sec) * 1000000000 + (now.tv_nsec - g_startTime.m_time.tv_nsec);
 
 	return ticks;
 }
@@ -65,8 +64,17 @@ void HighRezTimer::sleep(Second sec)
 
 Second HighRezTimer::getCurrentTime()
 {
-	// Second(ticks) / 1000.0
-	return Second(getNs()) * 1e-9;
+	return Second(getNs()) / 1000000000.0;
+}
+
+U64 HighRezTimer::getCurrentTimeMs()
+{
+	return getNs() * 1000000;
+}
+
+U64 HighRezTimer::getCurrentTimeUs()
+{
+	return getNs() * 1000;
 }
 
 } // end namespace anki

+ 19 - 8
AnKi/Util/HighRezTimerWindows.cpp

@@ -31,31 +31,42 @@ public:
 	}
 };
 
-DummyInitTimer init;
+static DummyInitTimer g_init;
 
 } // namespace
 
-static U64 getMs()
+void HighRezTimer::sleep(Second sec)
+{
+	Sleep(U32(sec * 1000.0));
+}
+
+U64 HighRezTimer::getCurrentTimeMs()
 {
 	LARGE_INTEGER now;
 	QueryPerformanceCounter(&now);
 
-	now.QuadPart -= init.m_start.QuadPart;
+	now.QuadPart -= g_init.m_start.QuadPart;
 	now.QuadPart *= 1000;
-	now.QuadPart /= init.m_ticksPerSec.QuadPart;
+	now.QuadPart /= g_init.m_ticksPerSec.QuadPart;
 
 	return now.QuadPart;
 }
 
-void HighRezTimer::sleep(Second sec)
+U64 HighRezTimer::getCurrentTimeUs()
 {
-	Sleep(U32(sec * 1000.0));
+	LARGE_INTEGER now;
+	QueryPerformanceCounter(&now);
+
+	now.QuadPart -= g_init.m_start.QuadPart;
+	now.QuadPart *= 1000000;
+	now.QuadPart /= g_init.m_ticksPerSec.QuadPart;
+
+	return now.QuadPart;
 }
 
 Second HighRezTimer::getCurrentTime()
 {
-	// Second(ticks) / 1000.0
-	return Second(getMs()) * 0.001;
+	return Second(getCurrentTimeUs()) / 1000000.0;
 }
 
 } // end namespace anki