App.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include <AnKi/Core/App.h>
  6. #include <AnKi/Core/CVarSet.h>
  7. #include <AnKi/Core/GpuMemory/UnifiedGeometryBuffer.h>
  8. #include <AnKi/Util/Logger.h>
  9. #include <AnKi/Util/File.h>
  10. #include <AnKi/Util/Filesystem.h>
  11. #include <AnKi/Util/System.h>
  12. #include <AnKi/Util/Tracer.h>
  13. #include <AnKi/Util/HighRezTimer.h>
  14. #include <AnKi/Core/CoreTracer.h>
  15. #include <AnKi/Core/GpuMemory/RebarTransientMemoryPool.h>
  16. #include <AnKi/Core/GpuMemory/GpuVisibleTransientMemoryPool.h>
  17. #include <AnKi/Core/GpuMemory/GpuReadbackMemoryPool.h>
  18. #include <AnKi/Core/StatsSet.h>
  19. #include <AnKi/Window/NativeWindow.h>
  20. #include <AnKi/Core/MaliHwCounters.h>
  21. #include <AnKi/Window/Input.h>
  22. #include <AnKi/Scene/SceneGraph.h>
  23. #include <AnKi/Resource/ResourceManager.h>
  24. #include <AnKi/Physics/PhysicsWorld.h>
  25. #include <AnKi/Renderer/MainRenderer.h>
  26. #include <AnKi/Script/ScriptManager.h>
  27. #include <AnKi/Resource/ResourceFilesystem.h>
  28. #include <AnKi/Resource/AsyncLoader.h>
  29. #include <AnKi/Ui/UiManager.h>
  30. #include <AnKi/Ui/Canvas.h>
  31. #include <AnKi/Scene/DeveloperConsoleUiNode.h>
  32. #include <csignal>
  33. #if ANKI_OS_ANDROID
  34. # include <android_native_app_glue.h>
  35. #endif
  36. namespace anki {
  37. #if ANKI_OS_ANDROID
  38. /// The one and only android hack
  39. android_app* g_androidApp = nullptr;
  40. #endif
  41. StatCounter g_cpuTotalTimeStatVar(StatCategory::kTime, "CPU total", StatFlag::kMilisecond | StatFlag::kShowAverage | StatFlag::kMainThreadUpdates);
  42. static StatCounter g_cpuAllocatedMemStatVar(StatCategory::kCpuMem, "Total", StatFlag::kBytes);
  43. static StatCounter g_cpuAllocationCountStatVar(StatCategory::kCpuMem, "Allocations/frame", StatFlag::kBytes | StatFlag::kZeroEveryFrame);
  44. static StatCounter g_cpuFreesCountStatVar(StatCategory::kCpuMem, "Frees/frame", StatFlag::kBytes | StatFlag::kZeroEveryFrame);
  45. NumericCVar<U32> g_windowWidthCVar(CVarSubsystem::kCore, "Width", 1920, 16, 16 * 1024, "Width");
  46. NumericCVar<U32> g_windowHeightCVar(CVarSubsystem::kCore, "Height", 1080, 16, 16 * 1024, "Height");
  47. NumericCVar<U32> g_windowFullscreenCVar(CVarSubsystem::kCore, "WindowFullscreen", 1, 0, 2,
  48. "0: windowed, 1: borderless fullscreen, 2: exclusive fullscreen");
  49. NumericCVar<U32> g_targetFpsCVar(CVarSubsystem::kCore, "TargetFps", 60u, 1u, kMaxU32, "Target FPS");
  50. static NumericCVar<U32> g_jobThreadCountCVar(CVarSubsystem::kCore, "JobThreadCount", max(2u, getCpuCoresCount() / 2u), 2u, 1024u,
  51. "Number of job thread");
  52. NumericCVar<U32> g_displayStatsCVar(CVarSubsystem::kCore, "DisplayStats", 0, 0, 2, "Display stats, 0: None, 1: Simple, 2: Detailed");
  53. BoolCVar g_clearCachesCVar(CVarSubsystem::kCore, "ClearCaches", false, "Clear all caches");
  54. BoolCVar g_verboseLogCVar(CVarSubsystem::kCore, "VerboseLog", false, "Verbose logging");
  55. BoolCVar g_benchmarkModeCVar(CVarSubsystem::kCore, "BenchmarkMode", false, "Run in a benchmark mode. Fixed timestep, unlimited target FPS");
  56. NumericCVar<U32> g_benchmarkModeFrameCountCVar(CVarSubsystem::kCore, "BenchmarkModeFrameCount", 60 * 60 * 2, 1, kMaxU32,
  57. "How many frames the benchmark will run before it quits");
  58. BoolCVar g_meshletRenderingCVar(CVarSubsystem::kCore, "MeshletRendering", false, "Do meshlet culling and rendering");
  59. #if ANKI_PLATFORM_MOBILE
  60. static StatCounter g_maliGpuActiveStatVar(StatCategory::kGpuMisc, "Mali active cycles", StatFlag::kMainThreadUpdates);
  61. static StatCounter g_maliGpuReadBandwidthStatVar(StatCategory::kGpuMisc, "Mali read bandwidth", StatFlag::kMainThreadUpdates);
  62. static StatCounter g_maliGpuWriteBandwidthStatVar(StatCategory::kGpuMisc, "Mali write bandwidth", StatFlag::kMainThreadUpdates);
  63. static BoolCVar g_maliHwCountersCVar(CVarSubsystem::kCore, "MaliHwCounters", false, "Enable Mali counters");
  64. #endif
  65. void* App::statsAllocCallback(void* userData, void* ptr, PtrSize size, [[maybe_unused]] PtrSize alignment)
  66. {
  67. ANKI_ASSERT(userData);
  68. constexpr PtrSize kMaxAlignment = 64;
  69. struct alignas(kMaxAlignment) Header
  70. {
  71. PtrSize m_allocatedSize;
  72. Array<U8, kMaxAlignment - sizeof(PtrSize)> _m_padding;
  73. };
  74. static_assert(sizeof(Header) == kMaxAlignment, "See file");
  75. static_assert(alignof(Header) == kMaxAlignment, "See file");
  76. void* out = nullptr;
  77. if(ptr == nullptr)
  78. {
  79. // Need to allocate
  80. ANKI_ASSERT(size > 0);
  81. ANKI_ASSERT(alignment > 0 && alignment <= kMaxAlignment);
  82. const PtrSize newAlignment = kMaxAlignment;
  83. const PtrSize newSize = sizeof(Header) + size;
  84. // Allocate
  85. App* self = static_cast<App*>(userData);
  86. Header* allocation = static_cast<Header*>(self->m_originalAllocCallback(self->m_originalAllocUserData, nullptr, newSize, newAlignment));
  87. allocation->m_allocatedSize = size;
  88. ++allocation;
  89. out = static_cast<void*>(allocation);
  90. // Update stats
  91. g_cpuAllocatedMemStatVar.increment(size);
  92. g_cpuAllocationCountStatVar.increment(1);
  93. }
  94. else
  95. {
  96. // Need to free
  97. App* self = static_cast<App*>(userData);
  98. Header* allocation = static_cast<Header*>(ptr);
  99. --allocation;
  100. ANKI_ASSERT(allocation->m_allocatedSize > 0);
  101. // Update stats
  102. g_cpuAllocatedMemStatVar.decrement(allocation->m_allocatedSize);
  103. g_cpuFreesCountStatVar.increment(1);
  104. // Free
  105. self->m_originalAllocCallback(self->m_originalAllocUserData, allocation, 0, 0);
  106. }
  107. return out;
  108. }
  109. App::App(AllocAlignedCallback allocCb, void* allocCbUserData)
  110. {
  111. m_originalAllocCallback = allocCb;
  112. m_originalAllocUserData = allocCbUserData;
  113. }
  114. App::~App()
  115. {
  116. ANKI_CORE_LOGI("Destroying application");
  117. cleanup();
  118. }
  119. void App::cleanup()
  120. {
  121. SceneGraph::freeSingleton();
  122. ScriptManager::freeSingleton();
  123. MainRenderer::freeSingleton();
  124. UiManager::freeSingleton();
  125. GpuSceneMicroPatcher::freeSingleton();
  126. ResourceManager::freeSingleton();
  127. PhysicsWorld::freeSingleton();
  128. RebarTransientMemoryPool::freeSingleton();
  129. GpuVisibleTransientMemoryPool::freeSingleton();
  130. UnifiedGeometryBuffer::freeSingleton();
  131. GpuSceneBuffer::freeSingleton();
  132. GpuReadbackMemoryPool::freeSingleton();
  133. CoreThreadJobManager::freeSingleton();
  134. MaliHwCounters::freeSingleton();
  135. GrManager::freeSingleton();
  136. Input::freeSingleton();
  137. NativeWindow::freeSingleton();
  138. #if ANKI_TRACING_ENABLED
  139. CoreTracer::freeSingleton();
  140. #endif
  141. GlobalFrameIndex::freeSingleton();
  142. m_settingsDir.destroy();
  143. m_cacheDir.destroy();
  144. CoreMemoryPool::freeSingleton();
  145. DefaultMemoryPool::freeSingleton();
  146. }
  147. Error App::init()
  148. {
  149. const Error err = initInternal();
  150. if(err)
  151. {
  152. ANKI_CORE_LOGE("App initialization failed. Shutting down");
  153. cleanup();
  154. }
  155. return err;
  156. }
  157. Error App::initInternal()
  158. {
  159. StatsSet::getSingleton().initFromMainThread();
  160. Logger::getSingleton().enableVerbosity(g_verboseLogCVar.get());
  161. AllocAlignedCallback allocCb = m_originalAllocCallback;
  162. void* allocCbUserData = m_originalAllocUserData;
  163. initMemoryCallbacks(allocCb, allocCbUserData);
  164. DefaultMemoryPool::allocateSingleton(allocCb, allocCbUserData);
  165. CoreMemoryPool::allocateSingleton(allocCb, allocCbUserData);
  166. ANKI_CHECK(initDirs());
  167. // Print a message
  168. const char* buildType =
  169. #if ANKI_OPTIMIZE
  170. "optimized, "
  171. #else
  172. "NOT optimized, "
  173. #endif
  174. #if ANKI_DEBUG_SYMBOLS
  175. "dbg symbols, "
  176. #else
  177. "NO dbg symbols, "
  178. #endif
  179. #if ANKI_EXTRA_CHECKS
  180. "extra checks, "
  181. #else
  182. "NO extra checks, "
  183. #endif
  184. #if ANKI_TRACING_ENABLED
  185. "built with tracing";
  186. #else
  187. "NOT built with tracing";
  188. #endif
  189. ANKI_CORE_LOGI("Initializing application");
  190. ANKI_CORE_LOGI("\tBuild type %s", buildType);
  191. ANKI_CORE_LOGI("\tBuild time %s %s", __DATE__, __TIME__);
  192. ANKI_CORE_LOGI("\tCompiler %s", ANKI_COMPILER_STR);
  193. ANKI_CORE_LOGI("\tCommit %s", ANKI_REVISION);
  194. // Check SIMD support
  195. #if ANKI_SIMD_SSE && ANKI_COMPILER_GCC_COMPATIBLE
  196. if(!__builtin_cpu_supports("sse4.2"))
  197. {
  198. ANKI_CORE_LOGF("AnKi is built with sse4.2 support but your CPU doesn't support it. Try bulding without SSE support");
  199. }
  200. #endif
  201. ANKI_CORE_LOGI("Number of job threads: %u", g_jobThreadCountCVar.get());
  202. if(g_benchmarkModeCVar.get() && g_vsyncCVar.get())
  203. {
  204. ANKI_CORE_LOGW("Vsync is enabled and benchmark mode as well. Will turn vsync off");
  205. g_vsyncCVar.set(false);
  206. }
  207. GlobalFrameIndex::allocateSingleton();
  208. //
  209. // Core tracer
  210. //
  211. #if ANKI_TRACING_ENABLED
  212. ANKI_CHECK(CoreTracer::allocateSingleton().init(m_settingsDir));
  213. #endif
  214. //
  215. // Window
  216. //
  217. NativeWindowInitInfo nwinit;
  218. nwinit.m_width = g_windowWidthCVar.get();
  219. nwinit.m_height = g_windowHeightCVar.get();
  220. nwinit.m_depthBits = 0;
  221. nwinit.m_stencilBits = 0;
  222. nwinit.m_fullscreenDesktopRez = g_windowFullscreenCVar.get() > 0;
  223. nwinit.m_exclusiveFullscreen = g_windowFullscreenCVar.get() == 2;
  224. nwinit.m_targetFps = g_targetFpsCVar.get();
  225. NativeWindow::allocateSingleton();
  226. ANKI_CHECK(NativeWindow::getSingleton().init(nwinit));
  227. //
  228. // Input
  229. //
  230. Input::allocateSingleton();
  231. ANKI_CHECK(Input::getSingleton().init());
  232. //
  233. // ThreadPool
  234. //
  235. const Bool pinThreads = !ANKI_OS_ANDROID;
  236. CoreThreadJobManager::allocateSingleton(g_jobThreadCountCVar.get(), pinThreads);
  237. //
  238. // Graphics API
  239. //
  240. GrManagerInitInfo grInit;
  241. grInit.m_allocCallback = allocCb;
  242. grInit.m_allocCallbackUserData = allocCbUserData;
  243. grInit.m_cacheDirectory = m_cacheDir.toCString();
  244. ANKI_CHECK(GrManager::allocateSingleton().init(grInit));
  245. //
  246. // Mali HW counters
  247. //
  248. #if ANKI_PLATFORM_MOBILE
  249. if(ANKI_STATS_ENABLED && GrManager::getSingleton().getDeviceCapabilities().m_gpuVendor == GpuVendor::kArm && g_maliHwCountersCVar.get())
  250. {
  251. MaliHwCounters::allocateSingleton();
  252. }
  253. #endif
  254. //
  255. // GPU mem
  256. //
  257. UnifiedGeometryBuffer::allocateSingleton().init();
  258. GpuSceneBuffer::allocateSingleton().init();
  259. RebarTransientMemoryPool::allocateSingleton().init();
  260. GpuVisibleTransientMemoryPool::allocateSingleton();
  261. GpuReadbackMemoryPool::allocateSingleton();
  262. //
  263. // Physics
  264. //
  265. PhysicsWorld::allocateSingleton();
  266. ANKI_CHECK(PhysicsWorld::getSingleton().init(allocCb, allocCbUserData));
  267. //
  268. // Resources
  269. //
  270. #if !ANKI_OS_ANDROID
  271. // Add the location of the executable where the shaders are supposed to be
  272. String executableFname;
  273. ANKI_CHECK(getApplicationPath(executableFname));
  274. ANKI_CORE_LOGI("Executable path is: %s", executableFname.cstr());
  275. String extraPaths;
  276. getParentFilepath(executableFname, extraPaths);
  277. extraPaths += "|ankiprogbin"; // Shaders
  278. extraPaths += ":" ANKI_SOURCE_DIRECTORY "|EngineAssets,!AndroidProject"; // EngineAssets
  279. extraPaths += ":";
  280. extraPaths += g_dataPathsCVar.get();
  281. g_dataPathsCVar.set(extraPaths);
  282. #endif
  283. ANKI_CHECK(ResourceManager::allocateSingleton().init(allocCb, allocCbUserData));
  284. //
  285. // UI
  286. //
  287. ANKI_CHECK(UiManager::allocateSingleton().init(allocCb, allocCbUserData));
  288. //
  289. // GPU scene
  290. //
  291. ANKI_CHECK(GpuSceneMicroPatcher::allocateSingleton().init());
  292. //
  293. // Renderer
  294. //
  295. MainRendererInitInfo renderInit;
  296. renderInit.m_swapchainSize = UVec2(NativeWindow::getSingleton().getWidth(), NativeWindow::getSingleton().getHeight());
  297. renderInit.m_allocCallback = allocCb;
  298. renderInit.m_allocCallbackUserData = allocCbUserData;
  299. ANKI_CHECK(MainRenderer::allocateSingleton().init(renderInit));
  300. //
  301. // Script
  302. //
  303. ScriptManager::allocateSingleton(allocCb, allocCbUserData);
  304. //
  305. // Scene
  306. //
  307. ANKI_CHECK(SceneGraph::allocateSingleton().init(allocCb, allocCbUserData));
  308. ANKI_CORE_LOGI("Application initialized");
  309. return Error::kNone;
  310. }
  311. Error App::initDirs()
  312. {
  313. // Settings path
  314. #if !ANKI_OS_ANDROID
  315. String home;
  316. ANKI_CHECK(getHomeDirectory(home));
  317. m_settingsDir.sprintf("%s/.anki", &home[0]);
  318. #else
  319. m_settingsDir.sprintf("%s/.anki", g_androidApp->activity->internalDataPath);
  320. #endif
  321. if(!directoryExists(m_settingsDir.toCString()))
  322. {
  323. ANKI_CORE_LOGI("Creating settings dir \"%s\"", &m_settingsDir[0]);
  324. ANKI_CHECK(createDirectory(m_settingsDir.toCString()));
  325. }
  326. else
  327. {
  328. ANKI_CORE_LOGI("Using settings dir \"%s\"", &m_settingsDir[0]);
  329. }
  330. // Cache
  331. m_cacheDir.sprintf("%s/cache", &m_settingsDir[0]);
  332. const Bool cacheDirExists = directoryExists(m_cacheDir.toCString());
  333. if(g_clearCachesCVar.get() && cacheDirExists)
  334. {
  335. ANKI_CORE_LOGI("Will delete the cache dir and start fresh: %s", m_cacheDir.cstr());
  336. ANKI_CHECK(removeDirectory(m_cacheDir.toCString()));
  337. ANKI_CHECK(createDirectory(m_cacheDir.toCString()));
  338. }
  339. else if(!cacheDirExists)
  340. {
  341. ANKI_CORE_LOGI("Will create cache dir: %s", m_cacheDir.cstr());
  342. ANKI_CHECK(createDirectory(m_cacheDir.toCString()));
  343. }
  344. return Error::kNone;
  345. }
  346. Error App::mainLoop()
  347. {
  348. ANKI_CORE_LOGI("Entering main loop");
  349. Bool quit = false;
  350. Second prevUpdateTime = HighRezTimer::getCurrentTime();
  351. Second crntTime = prevUpdateTime;
  352. // Benchmark mode stuff:
  353. const Bool benchmarkMode = g_benchmarkModeCVar.get();
  354. Second aggregatedCpuTime = 0.0;
  355. Second aggregatedGpuTime = 0.0;
  356. constexpr U32 kBenchmarkFramesToGatherBeforeFlush = 60;
  357. U32 benchmarkFramesGathered = 0;
  358. File benchmarkCsvFile;
  359. CoreString benchmarkCsvFileFilename;
  360. if(benchmarkMode)
  361. {
  362. benchmarkCsvFileFilename.sprintf("%s/Benchmark.csv", m_settingsDir.cstr());
  363. ANKI_CHECK(benchmarkCsvFile.open(benchmarkCsvFileFilename, FileOpenFlag::kWrite));
  364. ANKI_CHECK(benchmarkCsvFile.writeText("CPU, GPU\n"));
  365. }
  366. while(!quit)
  367. {
  368. {
  369. ANKI_TRACE_SCOPED_EVENT(Frame);
  370. const Second startTime = HighRezTimer::getCurrentTime();
  371. prevUpdateTime = crntTime;
  372. crntTime = (!benchmarkMode) ? HighRezTimer::getCurrentTime() : (prevUpdateTime + 1.0_sec / 60.0_sec);
  373. // Update
  374. ANKI_CHECK(Input::getSingleton().handleEvents());
  375. // User update
  376. ANKI_CHECK(userMainLoop(quit, crntTime - prevUpdateTime));
  377. ANKI_CHECK(SceneGraph::getSingleton().update(prevUpdateTime, crntTime));
  378. // Render
  379. TexturePtr presentableTex = GrManager::getSingleton().acquireNextPresentableTexture();
  380. ANKI_CHECK(MainRenderer::getSingleton().render(presentableTex.get()));
  381. // If we get stats exclude the time of GR because it forces some GPU-CPU serialization. We don't want to count that
  382. Second grTime = 0.0;
  383. if(benchmarkMode || g_displayStatsCVar.get() > 0) [[unlikely]]
  384. {
  385. grTime = HighRezTimer::getCurrentTime();
  386. }
  387. GrManager::getSingleton().swapBuffers();
  388. if(benchmarkMode || g_displayStatsCVar.get() > 0) [[unlikely]]
  389. {
  390. grTime = HighRezTimer::getCurrentTime() - grTime;
  391. }
  392. RebarTransientMemoryPool::getSingleton().endFrame();
  393. UnifiedGeometryBuffer::getSingleton().endFrame();
  394. GpuSceneBuffer::getSingleton().endFrame();
  395. GpuVisibleTransientMemoryPool::getSingleton().endFrame();
  396. GpuReadbackMemoryPool::getSingleton().endFrame();
  397. // Sleep
  398. const Second endTime = HighRezTimer::getCurrentTime();
  399. const Second frameTime = endTime - startTime;
  400. g_cpuTotalTimeStatVar.set((frameTime - grTime) * 1000.0);
  401. if(!benchmarkMode) [[likely]]
  402. {
  403. const Second timerTick = 1.0_sec / Second(g_targetFpsCVar.get());
  404. if(frameTime < timerTick)
  405. {
  406. ANKI_TRACE_SCOPED_EVENT(TimerTickSleep);
  407. HighRezTimer::sleep(timerTick - frameTime);
  408. }
  409. }
  410. // Benchmark stats
  411. else
  412. {
  413. aggregatedCpuTime += frameTime - grTime;
  414. aggregatedGpuTime += 0; // TODO
  415. ++benchmarkFramesGathered;
  416. if(benchmarkFramesGathered >= kBenchmarkFramesToGatherBeforeFlush)
  417. {
  418. aggregatedCpuTime = aggregatedCpuTime / Second(kBenchmarkFramesToGatherBeforeFlush) * 1000.0;
  419. aggregatedGpuTime = aggregatedGpuTime / Second(kBenchmarkFramesToGatherBeforeFlush) * 1000.0;
  420. ANKI_CHECK(benchmarkCsvFile.writeTextf("%f,%f\n", aggregatedCpuTime, aggregatedGpuTime));
  421. benchmarkFramesGathered = 0;
  422. aggregatedCpuTime = 0.0;
  423. aggregatedGpuTime = 0.0;
  424. }
  425. }
  426. // Stats
  427. #if ANKI_PLATFORM_MOBILE
  428. if(MaliHwCounters::isAllocated())
  429. {
  430. MaliHwCountersOut out;
  431. MaliHwCounters::getSingleton().sample(out);
  432. g_maliGpuActiveStatVar.set(out.m_gpuActive);
  433. g_maliGpuReadBandwidthStatVar.set(out.m_readBandwidth);
  434. g_maliGpuWriteBandwidthStatVar.set(out.m_writeBandwidth);
  435. }
  436. #endif
  437. StatsSet::getSingleton().endFrame();
  438. ++GlobalFrameIndex::getSingleton().m_value;
  439. if(benchmarkMode) [[unlikely]]
  440. {
  441. if(GlobalFrameIndex::getSingleton().m_value >= g_benchmarkModeFrameCountCVar.get())
  442. {
  443. quit = true;
  444. }
  445. }
  446. }
  447. #if ANKI_TRACING_ENABLED
  448. static U64 frame = 1;
  449. CoreTracer::getSingleton().flushFrame(frame++);
  450. #endif
  451. }
  452. if(benchmarkMode) [[unlikely]]
  453. {
  454. ANKI_CORE_LOGI("Benchmark file saved in: %s", benchmarkCsvFileFilename.cstr());
  455. }
  456. return Error::kNone;
  457. }
  458. void App::initMemoryCallbacks(AllocAlignedCallback& allocCb, void*& allocCbUserData)
  459. {
  460. if(ANKI_STATS_ENABLED && g_displayStatsCVar.get() > 1)
  461. {
  462. allocCb = statsAllocCallback;
  463. allocCbUserData = this;
  464. }
  465. else
  466. {
  467. // Leave the default
  468. }
  469. }
  470. Bool App::toggleDeveloperConsole()
  471. {
  472. SceneNode& node = SceneGraph::getSingleton().findSceneNode("_DevConsole");
  473. static_cast<DeveloperConsoleUiNode&>(node).toggleConsole();
  474. m_consoleEnabled = static_cast<DeveloperConsoleUiNode&>(node).isConsoleEnabled();
  475. return m_consoleEnabled;
  476. }
  477. } // end namespace anki