VulkanRaytracingCycles 0.0.0
Cycles Render Engine With VulkanRaytracingShaderModules. ( Experiment , in progress)
log.cpp
Go to the documentation of this file.
1#include "pch_mm.h"
2#include "working_mm.h"
3
4#include "log.hpp"
5#include "global.hpp"
6
7
8
9#ifdef AEOLUS
10#include "aeolus/incomplete.h"
11#include <filesystem>
12extern bool LivePrintOff;
13
14#include "aeolus/AllocatorVk.h"
16#endif
17extern bool FilePrintOn;
18
19void testit(const char* fmt, ...)
20{
21
22 va_list args;
23 va_start(args, fmt);
24 vprintf(fmt, args);
25 va_end(args);
26
27 printf("\x1b[0m\n");
28
29}
30
31
32
33#ifdef _WIN32
34#define VC_EXTRALEAN
35#define WIN32_LEAN_AND_MEAN
36#include <windows.h>
37#if AEOLUS
38#include "Python.h"
39#endif
40#endif
41
42
43void log_init(void)
44{
45
46#ifdef _WIN32
47 // AllocConsole();
48 // AttachConsole(GetCurrentProcessId());
49 // freopen("CON", "w", stdout);
50 // freopen("CON", "w", stderr);
51
52 // enable ANSI codes in windows console (conhost.exe)
53 // http://www.nivot.org/blog/post/2016/02/04/Windows-10-TH2-(v1511)-Console-Host-Enhancements
54 DWORD mode;
55 HANDLE console = GetStdHandle(-11); // STD_OUTPUT_HANDLE
56 GetConsoleMode(console, &mode);
57 mode = mode | 4; // ENABLE_VIRTUAL_TERMINAL_PROCESSING
58 SetConsoleMode(console, mode);
59#endif
62}
63
64
66{
67
68
69 std::this_thread::sleep_for(std::chrono::milliseconds(1000));
70#ifdef AEOLUS
71 //des.~DeallocatorVk();
72 //des.Holocaust();
73 PyErr_SetString(PyExc_TypeError, "BAD");
74 PyErr_NoMemory();
75#else
76 exit(-1);
77#endif
78 //
79
80}
81
82
83
84// https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
85void log_out(const char* file, int line, enum LOG_LEVEL level, const char* fmt, ...)
86{
87 struct timespec tv;
88
89 double now = (double)sys_time() / (double)sys_ticksecond;
90 tv.tv_nsec = long(fmod(now, 1.0) * 1000000000.0f);
91 tv.tv_sec = (uint64_t)now;
92
93 printf("%s:%d %s %" PRIu64 ".%09ld ", file, line,
94 log_label(level),
95 (uint64_t)tv.tv_sec, tv.tv_nsec);
96
97 va_list args;
98 va_start(args, fmt);
99 vprintf(fmt, args);
100 va_end(args);
101
102 printf("\x1b[0m\n");
103
104}
105#ifdef AEOLUS
106class SynchronizedFile {
107
108 SRWLOCK SrwLock;
109 std::ofstream stream;
110public:
111 SynchronizedFile() {
112
113 InitializeSRWLock(&SrwLock);
114
115 std::string path = std::string(LOG_THREAD_FILE) + "threadID" + std::to_string(_threadid) + ".log";
116 std::filesystem::create_directories(LOG_THREAD_FILE); //add directories based on the object path (without this line it will not work)
117
118 stream.open(path);
119 if (!stream.is_open() || !stream.good())
120 {
121 log_bad("file failed to create %s\n", path);
122 }
123 stream << "Open Log " << path << "\n";
124
125 }
126
127 void write(const char* file, int line, enum LOG_LEVEL level, const char* message) {
128
130 AcquireSRWLockExclusive(&SrwLock);
131 stream << file << "::" << line << "::" << log_label(level) << " " << message;
132 stream.flush();
133 ReleaseSRWLockExclusive(&SrwLock);
134
135 }
136 void save(const char* file, const char* message) {
137
139 AcquireSRWLockExclusive(&SrwLock);
140
141 std::string path = std::string(LOG_THREAD_FILE) + std::string(file) + ".save";
142 std::filesystem::create_directories(LOG_THREAD_FILE); //add directories based on the object path (without this line it will not work)
143 std::ofstream _stream;
144 _stream.open(path);
145 if (!_stream.is_open() || !_stream.good())
146 {
147 log_bad("file failed to create %s\n", path);
148 }
149 _stream << message;
150 _stream.flush();
151 _stream.close();
152 ReleaseSRWLockExclusive(&SrwLock);
153
154 }
155private:
156 std::string _path;
157};
158
159static auto syncFile = std::make_shared<SynchronizedFile>();
160
161void log__save(const char* file, const char* fmt)
162{
163 syncFile->save(file, fmt);
164}
165void log__thread(const char* file, int line, enum LOG_LEVEL level, const char* fmt, ...)
166{
167#ifdef AEOLUS
168 if (!LivePrintOff) {
169#endif
170 char message[512] = { 0 };
171 va_list args;
172 va_start(args, fmt);
173 vsprintf_s(message, fmt, args);
174 va_end(args);
175 syncFile->write(file, line, level, message);
176
177#ifdef AEOLUS
178 }
179#endif
180}
181#else
182void log__thread(const char* file, int line, enum LOG_LEVEL level, const char* fmt, ...)
183{
184
185
186 printf("%s:%d %s ", file, line, log_label(level));
187
188 va_list args;
189 va_start(args, fmt);
190 vprintf(fmt, args);
191 va_end(args);
192
193 printf("\x1b[0m\n");
194
195#ifdef AEOLUS
196}
197#endif
198}
199
200#endif
201
202
203inline std::wstring to_wchar(const char* text) {
204 //const char* text_char = "example of mbstowcs";
205 size_t length = strlen(text);
206 std::wstring text_wchar(length, L'#');
207 //#pragma warning (disable : 4996)
208 // Or add to the preprocessor: _CRT_SECURE_NO_WARNINGS
209 mbstowcs(&text_wchar[0], text, length);
210 return text_wchar;
211};
212
213void log__bad(const char* file, int line, enum LOG_LEVEL level, const char* fmt, ...)
214{
215
216
217 char message[512] = { 0 };
218
219 va_list args;
220 va_start(args, fmt);
221 vsprintf_s(message, fmt, args);
222 va_end(args);
223
224 int on_button;
225#ifdef UNICODE
226 on_button = MessageBox(NULL, to_wchar((std::string(file) + ":" + std::to_string(line) + " \n " + message).c_str()).c_str(),
227#else
228 on_button = MessageBox(NULL, (std::string(file) + ":" + std::to_string(line) + " \n " + message).c_str(),
229#endif
230 TEXT("!Bad!"), MB_YESNO | MB_ICONQUESTION);
231
232 if (on_button == IDYES)
233 MessageBox(NULL, TEXT("Be Killed!"),
234 TEXT("exit."), MB_OK);
235 else MessageBox(NULL, TEXT("Be Killed!"),
236 TEXT("exit."), MB_OK);
237
238 exitFatal();
239
240
241}
242
243void log__vkabad(const char* file, int line, enum LOG_LEVEL level, VkResult code, const char* fmt, ...)
244{
245
246
247 printf("%s:%d %s VkaCode::%s ", file, line, log_label(level), errorString(code));
248
249 va_list args;
250 va_start(args, fmt);
251 vprintf(fmt, args);
252 va_end(args);
253
254 printf("\x1b[0m\n");
255
256 exitFatal();
257 //PyErr_BadArgument();
258 //PyErr_SetString(PyExc_TypeError, "BAD");
259 //throw ;
260
261}
262
263void log__once(const char* file, int line, enum LOG_LEVEL level, const char* fmt, ...)
264{
265
266
267 printf("%s:%d %s ", file, line, log_label(level));
268
269 va_list args;
270 va_start(args, fmt);
271 vprintf(fmt, args);
272 va_end(args);
273
274 printf("\x1b[0m\n");
275
276}
277
278
279void log__vs(const char* file, int line, enum LOG_LEVEL level, const char* fmt, ...)
280{
281
282
283 char message[512] = { 0 };
284 std::string mg = std::string(file) + "::" + std::to_string(line);
285
286
287 va_list args;
288 va_start(args, fmt);
289 vsprintf_s(message, fmt, args);
290 va_end(args);
291
292 mg += std::string(" ") + message;
293
294 OutputDebugString(mg.c_str());
295
296}
297
298
299
300const char* errorString(VkResult errorCode)
301{
302 switch (errorCode)
303 {
304#define STR(r) case VK_ ##r: return #r
305 STR(NOT_READY);
306 STR(TIMEOUT);
307 STR(EVENT_SET);
308 STR(EVENT_RESET);
309 STR(INCOMPLETE);
310 STR(ERROR_OUT_OF_HOST_MEMORY);
311 STR(ERROR_OUT_OF_DEVICE_MEMORY);
312 STR(ERROR_INITIALIZATION_FAILED);
313 STR(ERROR_DEVICE_LOST);
314 STR(ERROR_MEMORY_MAP_FAILED);
315 STR(ERROR_LAYER_NOT_PRESENT);
316 STR(ERROR_EXTENSION_NOT_PRESENT);
317 STR(ERROR_FEATURE_NOT_PRESENT);
318 STR(ERROR_INCOMPATIBLE_DRIVER);
319 STR(ERROR_TOO_MANY_OBJECTS);
320 STR(ERROR_FORMAT_NOT_SUPPORTED);
321 STR(ERROR_SURFACE_LOST_KHR);
322 STR(ERROR_NATIVE_WINDOW_IN_USE_KHR);
323 STR(SUBOPTIMAL_KHR);
324 STR(ERROR_OUT_OF_DATE_KHR);
325 STR(ERROR_INCOMPATIBLE_DISPLAY_KHR);
326 STR(ERROR_VALIDATION_FAILED_EXT);
327 STR(ERROR_INVALID_SHADER_NV);
328#undef STR
329 default:
330 return "UNKNOWN_ERROR_";
331 }
332}
void sys_time_init(void)
Definition: global.cpp:63
uint64_t sys_time(void)
Definition: global.cpp:56
uint64_t sys_ticksecond
Definition: global.cpp:54
void log__thread(const char *file, int line, enum LOG_LEVEL level, const char *fmt,...)
Definition: log.cpp:182
void log__bad(const char *file, int line, enum LOG_LEVEL level, const char *fmt,...)
Definition: log.cpp:213
void log_init(void)
Definition: log.cpp:43
void exitFatal()
Definition: log.cpp:65
const char * errorString(VkResult errorCode)
Definition: log.cpp:300
void log_out(const char *file, int line, enum LOG_LEVEL level, const char *fmt,...)
Definition: log.cpp:85
std::wstring to_wchar(const char *text)
Definition: log.cpp:203
bool FilePrintOn
void log__vkabad(const char *file, int line, enum LOG_LEVEL level, VkResult code, const char *fmt,...)
Definition: log.cpp:243
void log__once(const char *file, int line, enum LOG_LEVEL level, const char *fmt,...)
Definition: log.cpp:263
#define STR(r)
void testit(const char *fmt,...)
Definition: log.cpp:19
void log__vs(const char *file, int line, enum LOG_LEVEL level, const char *fmt,...)
Definition: log.cpp:279
#define log_bad(...)
Definition: log.hpp:37
void log__save(const char *file, const char *fmt)
LOG_LEVEL
Definition: log.hpp:53
#define des