Browse Source

Add a benchmark mode

Panagiotis Christopoulos Charitos 3 years ago
parent
commit
2037256a87
3 changed files with 66 additions and 8 deletions
  1. 60 5
      AnKi/Core/App.cpp
  2. 3 0
      AnKi/Core/ConfigVars.defs.h
  3. 3 3
      AnKi/Gr/Vulkan/GrManagerImpl.cpp

+ 60 - 5
AnKi/Core/App.cpp

@@ -223,6 +223,12 @@ Error App::initInternal(AllocAlignedCallback allocCb, void* allocCbUserData)
 
 
 	ANKI_CORE_LOGI("Number of job threads: %u", m_config->getCoreJobThreadCount());
 	ANKI_CORE_LOGI("Number of job threads: %u", m_config->getCoreJobThreadCount());
 
 
+	if(m_config->getCoreBenchmarkMode() && m_config->getGrVsync())
+	{
+		ANKI_CORE_LOGW("Vsync is enabled and benchmark mode as well. Will turn vsync off");
+		m_config->setGrVsync(false);
+	}
+
 	//
 	//
 	// Core tracer
 	// Core tracer
 	//
 	//
@@ -450,6 +456,21 @@ Error App::mainLoop()
 	Second prevUpdateTime = HighRezTimer::getCurrentTime();
 	Second prevUpdateTime = HighRezTimer::getCurrentTime();
 	Second crntTime = prevUpdateTime;
 	Second crntTime = prevUpdateTime;
 
 
+	// Benchmark mode stuff:
+	const Bool benchmarkMode = m_config->getCoreBenchmarkMode();
+	Second aggregatedCpuTime = 0.0;
+	Second aggregatedGpuTime = 0.0;
+	constexpr U32 kBenchmarkFramesToGatherBeforeFlush = 60;
+	U32 benchmarkFramesGathered = 0;
+	File benchmarkCsvFile;
+	StringRaii benchmarkCsvFileFilename(&m_mainPool);
+	if(benchmarkMode)
+	{
+		benchmarkCsvFileFilename.sprintf("%s/Benchmark.csv", m_settingsDir.cstr());
+		ANKI_CHECK(benchmarkCsvFile.open(benchmarkCsvFileFilename, FileOpenFlag::kWrite));
+		ANKI_CHECK(benchmarkCsvFile.writeText("CPU, GPU\n"));
+	}
+
 	while(!quit)
 	while(!quit)
 	{
 	{
 		{
 		{
@@ -457,7 +478,8 @@ Error App::mainLoop()
 			const Second startTime = HighRezTimer::getCurrentTime();
 			const Second startTime = HighRezTimer::getCurrentTime();
 
 
 			prevUpdateTime = crntTime;
 			prevUpdateTime = crntTime;
-			crntTime = HighRezTimer::getCurrentTime();
+			crntTime =
+				ANKI_LIKELY(!benchmarkMode) ? HighRezTimer::getCurrentTime() : (prevUpdateTime + 1.0_sec / 60.0_sec);
 
 
 			// Update
 			// Update
 			ANKI_CHECK(m_input->handleEvents());
 			ANKI_CHECK(m_input->handleEvents());
@@ -502,11 +524,31 @@ Error App::mainLoop()
 			// Sleep
 			// Sleep
 			const Second endTime = HighRezTimer::getCurrentTime();
 			const Second endTime = HighRezTimer::getCurrentTime();
 			const Second frameTime = endTime - startTime;
 			const Second frameTime = endTime - startTime;
-			const Second timerTick = 1.0 / Second(m_config->getCoreTargetFps());
-			if(frameTime < timerTick)
+			if(ANKI_LIKELY(!benchmarkMode))
 			{
 			{
-				ANKI_TRACE_SCOPED_EVENT(TIMER_TICK_SLEEP);
-				HighRezTimer::sleep(timerTick - frameTime);
+				const Second timerTick = 1.0_sec / Second(m_config->getCoreTargetFps());
+				if(frameTime < timerTick)
+				{
+					ANKI_TRACE_SCOPED_EVENT(TIMER_TICK_SLEEP);
+					HighRezTimer::sleep(timerTick - frameTime);
+				}
+			}
+			// Benchmark stats
+			else
+			{
+				aggregatedCpuTime += frameTime;
+				aggregatedGpuTime += m_renderer->getStats().m_renderingGpuTime;
+				++benchmarkFramesGathered;
+				if(benchmarkFramesGathered >= kBenchmarkFramesToGatherBeforeFlush)
+				{
+					aggregatedCpuTime = aggregatedCpuTime / Second(kBenchmarkFramesToGatherBeforeFlush) * 1000.0;
+					aggregatedGpuTime = aggregatedGpuTime / Second(kBenchmarkFramesToGatherBeforeFlush) * 1000.0;
+					ANKI_CHECK(benchmarkCsvFile.writeTextf("%f,%f\n", aggregatedCpuTime, aggregatedGpuTime));
+
+					benchmarkFramesGathered = 0;
+					aggregatedCpuTime = 0.0;
+					aggregatedGpuTime = 0.0;
+				}
 			}
 			}
 
 
 			// Stats
 			// Stats
@@ -560,6 +602,14 @@ Error App::mainLoop()
 #endif
 #endif
 
 
 			++m_globalTimestamp;
 			++m_globalTimestamp;
+
+			if(ANKI_UNLIKELY(benchmarkMode))
+			{
+				if(m_globalTimestamp >= m_config->getCoreBenchmarkModeFrameCount())
+				{
+					quit = true;
+				}
+			}
 		}
 		}
 
 
 #if ANKI_ENABLE_TRACE
 #if ANKI_ENABLE_TRACE
@@ -568,6 +618,11 @@ Error App::mainLoop()
 #endif
 #endif
 	}
 	}
 
 
+	if(ANKI_UNLIKELY(benchmarkMode))
+	{
+		ANKI_CORE_LOGI("Benchmark file saved it: %s", benchmarkCsvFileFilename.cstr());
+	}
+
 	return Error::kNone;
 	return Error::kNone;
 }
 }
 
 

+ 3 - 0
AnKi/Core/ConfigVars.defs.h

@@ -23,3 +23,6 @@ ANKI_CONFIG_VAR_U32(CoreJobThreadCount, max(2u, getCpuCoresCount() / 2u), 2u, 10
 ANKI_CONFIG_VAR_U32(CoreDisplayStats, 0, 0, 2, "Display stats, 0: None, 1: Simple, 2: Detailed")
 ANKI_CONFIG_VAR_U32(CoreDisplayStats, 0, 0, 2, "Display stats, 0: None, 1: Simple, 2: Detailed")
 ANKI_CONFIG_VAR_BOOL(CoreClearCaches, false, "Clear all caches")
 ANKI_CONFIG_VAR_BOOL(CoreClearCaches, false, "Clear all caches")
 ANKI_CONFIG_VAR_BOOL(CoreVerboseLog, false, "Verbose logging")
 ANKI_CONFIG_VAR_BOOL(CoreVerboseLog, false, "Verbose logging")
+ANKI_CONFIG_VAR_BOOL(CoreBenchmarkMode, false, "Run in a benchmark mode. Fixed timestep, unlimited target FPS")
+ANKI_CONFIG_VAR_U32(CoreBenchmarkModeFrameCount, 60 * 60 * 2, 1, kMaxU32,
+					"How many frames the benchmark will run before it quits")

+ 3 - 3
AnKi/Gr/Vulkan/GrManagerImpl.cpp

@@ -1129,14 +1129,14 @@ Error GrManagerImpl::initMemory()
 	vkGetPhysicalDeviceMemoryProperties(m_physicalDevice, &m_memoryProperties);
 	vkGetPhysicalDeviceMemoryProperties(m_physicalDevice, &m_memoryProperties);
 
 
 	// Print some info
 	// Print some info
-	ANKI_VK_LOGI("Vulkan memory info:");
+	ANKI_VK_LOGV("Vulkan memory info:");
 	for(U32 i = 0; i < m_memoryProperties.memoryHeapCount; ++i)
 	for(U32 i = 0; i < m_memoryProperties.memoryHeapCount; ++i)
 	{
 	{
-		ANKI_VK_LOGI("\tHeap %u size %zu", i, m_memoryProperties.memoryHeaps[i].size);
+		ANKI_VK_LOGV("\tHeap %u size %zu", i, m_memoryProperties.memoryHeaps[i].size);
 	}
 	}
 	for(U32 i = 0; i < m_memoryProperties.memoryTypeCount; ++i)
 	for(U32 i = 0; i < m_memoryProperties.memoryTypeCount; ++i)
 	{
 	{
-		ANKI_VK_LOGI("\tMem type %u points to heap %u, flags %" ANKI_PRIb32, i,
+		ANKI_VK_LOGV("\tMem type %u points to heap %u, flags %" ANKI_PRIb32, i,
 					 m_memoryProperties.memoryTypes[i].heapIndex,
 					 m_memoryProperties.memoryTypes[i].heapIndex,
 					 ANKI_FORMAT_U32(m_memoryProperties.memoryTypes[i].propertyFlags));
 					 ANKI_FORMAT_U32(m_memoryProperties.memoryTypes[i].propertyFlags));
 	}
 	}