-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwiInitializer.cpp
More file actions
208 lines (186 loc) · 7.05 KB
/
Copy pathwiInitializer.cpp
File metadata and controls
208 lines (186 loc) · 7.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#include "wiInitializer.h"
#include "Simtary.h"
#include <thread>
#include <atomic>
#if !defined(_M_ARM64) && (defined(PLATFORM_WINDOWS_DESKTOP) || defined(PLATFORM_LINUX))
#define CPUINFO_AVAILABLE
#include "Utility/cpuinfo.hpp"
#endif // defined(PLATFORM_WINDOWS_DESKTOP) || defined(PLATFORM_LINUX)
namespace wi::initializer
{
static std::atomic_bool initializationStarted{ false };
static wi::jobsystem::context ctx;
static wi::Timer timer;
static std::atomic_bool systems[INITIALIZED_SYSTEM_COUNT]{};
void InitializeComponentsImmediate()
{
if (IsInitializeFinished())
return;
if (!initializationStarted.load())
{
InitializeComponentsAsync();
}
WaitForInitializationsToFinish();
}
void InitializeComponentsAsync()
{
if (IsInitializeFinished())
return;
timer.record();
initializationStarted.store(true);
#if defined(PLATFORM_WINDOWS_DESKTOP)
static constexpr const char* platform_string = "Windows";
#elif defined(PLATFORM_LINUX)
static constexpr const char* platform_string = "Linux";
#elif defined(PLATFORM_PS5)
static constexpr const char* platform_string = "PS5";
#elif defined(PLATFORM_XBOX)
static constexpr const char* platform_string = "Xbox";
#elif defined(PLATFORM_APPLE)
static constexpr const char* platform_string = "MacOS";
#endif // PLATFORM
#if defined(_MSC_VER) && defined(__clang__)
static constexpr const char* compiler_string = "CLANG-CL";
#elif defined(__clang__)
static constexpr const char* compiler_string = "CLANG";
#elif defined(_MSC_VER)
static constexpr const char* compiler_string = "MSVC";
#elif defined(__GNUC__)
static constexpr const char* compiler_string = "GCC";
#else
static constexpr const char* compiler_string = "UNKNOWN";
#endif
wilog("\n[wi::initializer] Initializing HMMWV4, please wait...\nVersion: %s\nPlatform: %s\nCompiler: %s", wi::version::GetVersionString(), platform_string, compiler_string);
StackString<1024> cpustring;
#ifdef CPUINFO_AVAILABLE
CPUInfo cpuinfo;
cpustring.push_back("\nCPU: ");
cpustring.push_back(cpuinfo.model().c_str());
cpustring.push_back("\n\tFeatures available: ");
if (cpuinfo.haveSSE())
{
cpustring.push_back("SSE; ");
}
if (cpuinfo.haveSSE2())
{
cpustring.push_back("SSE 2; ");
}
if (cpuinfo.haveSSE3())
{
cpustring.push_back("SSE 3; ");
}
if (cpuinfo.haveSSE41())
{
cpustring.push_back("SSE 4.1; ");
}
if (cpuinfo.haveSSE42())
{
cpustring.push_back("SSE 4.2; ");
}
if (cpuinfo.haveAVX())
{
cpustring.push_back("AVX; ");
}
if (cpuinfo.haveFMA3())
{
cpustring.push_back("FMA3; ");
}
if (cpuinfo.haveF16C())
{
cpustring.push_back("F16C; ");
}
if (cpuinfo.haveAVX2())
{
cpustring.push_back("AVX 2; ");
}
if (cpuinfo.haveAVX512F())
{
cpustring.push_back("AVX 512; ");
}
#else
cpustring.push_back("\nCPU: unrecognized");
#endif // CPUINFO_AVAILABLE
cpustring.push_back("\n\tFeatures used: ");
#ifdef _XM_SSE_INTRINSICS_
cpustring.push_back("SSE; ");
cpustring.push_back("SSE 2; ");
#endif // _XM_SSE_INTRINSICS_
#ifdef _XM_SSE3_INTRINSICS_
cpustring.push_back("SSE 3; ");
#endif // _XM_SSE3_INTRINSICS_
#ifdef _XM_SSE4_INTRINSICS_
cpustring.push_back("SSE 4.1; ");
#endif // _XM_SSE4_INTRINSICS_
#ifdef _XM_AVX_INTRINSICS_
cpustring.push_back("AVX; ");
#endif // _XM_AVX_INTRINSICS_
#ifdef _XM_FMA3_INTRINSICS_
cpustring.push_back("FMA3; ");
#endif // _XM_FMA3_INTRINSICS_
#ifdef _XM_F16C_INTRINSICS_
cpustring.push_back("F16C; ");
#endif // _XM_F16C_INTRINSICS_
#ifdef _XM_AVX2_INTRINSICS_
cpustring.push_back("AVX 2; ");
#endif // _XM_AVX2_INTRINSICS_
#ifdef _XM_ARM_NEON_INTRINSICS_
cpustring.push_back("NEON; ");
#endif // _XM_ARM_NEON_INTRINSICS_
wi::backlog::post(cpustring.c_str());
if (!XMVerifyCPUSupport())
{
wilog_messagebox("XMVerifyCPUSupport() failed! This means that your CPU doesn't support a required feature! %s", cpustring.c_str());
}
wilog("\nRAM: %s", wi::helper::GetMemorySizeText(wi::helper::GetMemoryUsage().total_physical).c_str());
size_t shaderdump_count = wi::renderer::GetShaderDumpCount();
if (shaderdump_count > 0)
{
wilog("\nEmbedded shaders found: %d", (int)shaderdump_count);
}
else
{
wilog("\nNo embedded shaders found, shaders will be compiled at runtime if needed.\n\tShader source path: %s\n\tShader binary path: %s", wi::renderer::GetShaderSourcePath().c_str(), wi::renderer::GetShaderPath().c_str());
}
#ifdef _DEBUG
wilog("\nNumber of shared allocators (there is one per object type): %d", (int)wi::allocator::get_shared_allocator_count());
#endif // _DEBUG
wi::backlog::post("");
wi::jobsystem::Initialize();
wi::backlog::post("");
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { wi::image::Initialize(); systems[INITIALIZED_SYSTEM_IMAGE].store(true); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { wi::input::Initialize(); systems[INITIALIZED_SYSTEM_INPUT].store(true); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { wi::renderer::Initialize(); systems[INITIALIZED_SYSTEM_RENDERER].store(true); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { wi::texturehelper::Initialize(); systems[INITIALIZED_SYSTEM_TEXTUREHELPER].store(true); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { wi::HairParticleSystem::Initialize(); systems[INITIALIZED_SYSTEM_HAIRPARTICLESYSTEM].store(true); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { wi::EmittedParticleSystem::Initialize(); systems[INITIALIZED_SYSTEM_EMITTEDPARTICLESYSTEM].store(true); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { wi::Ocean::Initialize(); systems[INITIALIZED_SYSTEM_OCEAN].store(true); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { wi::gpusortlib::Initialize(); systems[INITIALIZED_SYSTEM_GPUSORTLIB].store(true); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { wi::GPUBVH::Initialize(); systems[INITIALIZED_SYSTEM_GPUBVH].store(true); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { wi::physics::Initialize(); systems[INITIALIZED_SYSTEM_PHYSICS].store(true); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { wi::TrailRenderer::Initialize(); systems[INITIALIZED_SYSTEM_TRAILRENDERER].store(true); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { wi::GaussianSplatModel::Initialize(); systems[INITIALIZED_SYSTEM_GAUSSIAN_SPLAT].store(true); });
// Initialize these immediately:
wi::lua::Initialize(); systems[INITIALIZED_SYSTEM_LUA].store(true);
wi::audio::Initialize(); systems[INITIALIZED_SYSTEM_AUDIO].store(true);
wi::font::Initialize(); systems[INITIALIZED_SYSTEM_FONT].store(true);
std::thread([] {
wi::jobsystem::Wait(ctx);
wilog("\n[wi::initializer] HMMWV4 Initialized (%d ms)", (int)std::round(timer.elapsed()));
}).detach();
}
bool IsInitializeFinished(INITIALIZED_SYSTEM system)
{
if (system == INITIALIZED_SYSTEM_COUNT)
{
return initializationStarted.load() && !wi::jobsystem::IsBusy(ctx);
}
else
{
return systems[system].load();
}
}
void WaitForInitializationsToFinish()
{
wi::jobsystem::Wait(ctx);
}
}