Cogs.Core
Instrumentation.cpp
1#include "Instrumentation.h"
2#include "Context.h"
3#include "Services/Variables.h"
4
5#include "Rendering/IGraphicsDevice.h"
6#include "Rendering/CommandGroupAnnotation.h"
7
8#include "Renderer/IRenderer.h"
9
10#include "Foundation/HashFunctions.h"
11#include "Foundation/StringView.h"
12#include "Foundation/Reflection/TypeDatabase.h"
13
14#include <atomic>
15#include <cstdarg>
16#include <mutex>
17#include <unordered_map>
18
19#ifdef COGS_USE_NVTOOLSEXT
20#define WIN32_LEAN_AND_MEAN
21#include <Windows.h>
22#include <nvToolsExt.h>
23#endif
24
25#ifdef COGS_USE_INTEL_ITT
26#include <ittnotify.h>
27__itt_domain* itt_cogs_core_domain = nullptr;
28#endif
29
30void Cogs::Core::Instrumentation::initialize(Context * /*context*/)
31{
32 //TODO: Ensure we are able to run multiple contexts from the same or different
33 // threads without issues.
34
35#ifdef COGS_USE_MICROPROFILE
36 MicroProfileInit();
37 MicroProfileSetEnableAllGroups(true);
38 MicroProfileSetForceMetaCounters(true);
39#endif
40}
41
42void Cogs::Core::Instrumentation::initializeGpu(Context * context)
43{
44 (void)context;
45#ifdef COGS_USE_MICROPROFILE
46 auto device = context->device;
47 if (context->variables->get("profiling.gpu", false) && device->getType() == GraphicsDeviceType::Direct3D11) {
48 MicroProfileGpuInitD3D11((ID3D11Device *)device->getNativeDevice());
49 }
50#endif
51}
52
53void Cogs::Core::Instrumentation::beginGpuThread(IContext * /*context*/)
54{
55}
56
57void Cogs::Core::Instrumentation::initializeThread(const char* name)
58{
59 (void)name;
60
61#ifdef COGS_USE_SUPERLUMINAL
62 PerformanceAPI_SetCurrentThreadName(name);
63#endif
64
65#ifdef COGS_USE_MICROPROFILE
66 MicroProfileOnThreadCreate(name);
67#endif
68}
69
70void Cogs::Core::Instrumentation::destroyThread()
71{
72#ifdef COGS_USE_MICROPROFILE
73 MicroProfileOnThreadExit();
74#endif
75}
76
77void Cogs::Core::Instrumentation::beginGpuScope(IContext* iContext, const char* name)
78{
79 iContext->pushCommandGroupAnnotation(name);
80}
81
82void Cogs::Core::Instrumentation::endGpuScope(IContext* iContext)
83{
84 iContext->popCommandGroupAnnotation();
85}