summaryrefslogtreecommitdiffstats
path: root/external/optick/optick_common.h
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2019-04-30 13:12:35 +0200
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2019-04-30 13:12:35 +0200
commit868ba6279a20e4d1412c2d576c67400167de6694 (patch)
treea7090b2da96987c4c532c5bedf812df20f604964 /external/optick/optick_common.h
parentSecond iteration of changing to single-threaded model (diff)
downloadAltCraft-868ba6279a20e4d1412c2d576c67400167de6694.tar
AltCraft-868ba6279a20e4d1412c2d576c67400167de6694.tar.gz
AltCraft-868ba6279a20e4d1412c2d576c67400167de6694.tar.bz2
AltCraft-868ba6279a20e4d1412c2d576c67400167de6694.tar.lz
AltCraft-868ba6279a20e4d1412c2d576c67400167de6694.tar.xz
AltCraft-868ba6279a20e4d1412c2d576c67400167de6694.tar.zst
AltCraft-868ba6279a20e4d1412c2d576c67400167de6694.zip
Diffstat (limited to '')
-rw-r--r--external/optick/optick_common.h142
1 files changed, 142 insertions, 0 deletions
diff --git a/external/optick/optick_common.h b/external/optick/optick_common.h
new file mode 100644
index 0000000..4468911
--- /dev/null
+++ b/external/optick/optick_common.h
@@ -0,0 +1,142 @@
+#pragma once
+
+#include "optick.config.h"
+
+#if USE_OPTICK
+
+#include "optick.h"
+
+#include <cstdio>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#if defined(OPTICK_MSVC)
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#define NOMINMAX
+#include <windows.h>
+#endif
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Types
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+typedef signed char int8;
+typedef unsigned char uint8;
+typedef unsigned char byte;
+typedef short int16;
+typedef unsigned short uint16;
+typedef int int32;
+typedef unsigned int uint32;
+#if defined(OPTICK_MSVC)
+typedef __int64 int64;
+typedef unsigned __int64 uint64;
+#elif defined(OPTICK_GCC)
+typedef int64_t int64;
+typedef uint64_t uint64;
+#else
+#error Compiler is not supported
+#endif
+static_assert(sizeof(int8) == 1, "Invalid type size, int8");
+static_assert(sizeof(uint8) == 1, "Invalid type size, uint8");
+static_assert(sizeof(byte) == 1, "Invalid type size, byte");
+static_assert(sizeof(int16) == 2, "Invalid type size, int16");
+static_assert(sizeof(uint16) == 2, "Invalid type size, uint16");
+static_assert(sizeof(int32) == 4, "Invalid type size, int32");
+static_assert(sizeof(uint32) == 4, "Invalid type size, uint32");
+static_assert(sizeof(int64) == 8, "Invalid type size, int64");
+static_assert(sizeof(uint64) == 8, "Invalid type size, uint64");
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+typedef uint64 ThreadID;
+static const ThreadID INVALID_THREAD_ID = (ThreadID)-1;
+typedef uint32 ProcessID;
+static const ProcessID INVALID_PROCESS_ID = (ProcessID)-1;
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Memory
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#if defined(OPTICK_MSVC)
+#define OPTICK_ALIGN(N) __declspec( align( N ) )
+#elif defined(OPTICK_GCC)
+#define OPTICK_ALIGN(N) __attribute__((aligned(N)))
+#else
+#error Can not define OPTICK_ALIGN. Unknown platform.
+#endif
+#define OPTICK_CACHE_LINE_SIZE 64
+#define OPTICK_ALIGN_CACHE OPTICK_ALIGN(OPTICK_CACHE_LINE_SIZE)
+#define OPTICK_ARRAY_SIZE(ARR) (sizeof(ARR)/sizeof((ARR)[0]))
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#if defined(OPTICK_MSVC)
+#define OPTICK_NOINLINE __declspec(noinline)
+#elif defined(OPTICK_GCC)
+#define OPTICK_NOINLINE __attribute__((__noinline__))
+#else
+#error Compiler is not supported
+#endif
+////////////////////////////////////////////////////////////////////////
+// OPTICK_THREAD_LOCAL
+////////////////////////////////////////////////////////////////////////
+#if defined(OPTICK_MSVC)
+#define OPTICK_THREAD_LOCAL __declspec(thread)
+#elif defined(OPTICK_GCC)
+#define OPTICK_THREAD_LOCAL __thread
+#else
+#error Can not define OPTICK_THREAD_LOCAL. Unknown platform.
+#endif
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Asserts
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#if defined(OPTICK_MSVC)
+#define OPTICK_DEBUG_BREAK __debugbreak()
+#elif defined(OPTICK_GCC)
+#define OPTICK_DEBUG_BREAK __builtin_trap()
+#else
+ #error Can not define OPTICK_DEBUG_BREAK. Unknown platform.
+#endif
+#define OPTICK_UNUSED(x) (void)(x)
+#ifdef _DEBUG
+ #define OPTICK_ASSERT(arg, description) if (!(arg)) { OPTICK_DEBUG_BREAK; }
+ #define OPTICK_FAILED(description) { OPTICK_DEBUG_BREAK; }
+#else
+ #define OPTICK_ASSERT(arg, description)
+ #define OPTICK_FAILED(description)
+#endif
+#define OPTICK_VERIFY(arg, description, operation) if (!(arg)) { OPTICK_DEBUG_BREAK; operation; }
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Safe functions
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#if defined(OPTICK_LINUX) || defined(OPTICK_OSX)
+template<size_t sizeOfBuffer>
+inline int sprintf_s(char(&buffer)[sizeOfBuffer], const char* format, ...)
+{
+ va_list ap;
+ va_start(ap, format);
+ int result = vsnprintf(buffer, sizeOfBuffer, format, ap);
+ va_end(ap);
+ return result;
+}
+#endif
+
+#if defined(OPTICK_GCC)
+template<size_t sizeOfBuffer>
+inline int wcstombs_s(char(&buffer)[sizeOfBuffer], const wchar_t* src, size_t maxCount)
+{
+ return wcstombs(buffer, src, maxCount);
+}
+#endif
+
+#if defined(OPTICK_MSVC)
+template<size_t sizeOfBuffer>
+inline int wcstombs_s(char(&buffer)[sizeOfBuffer], const wchar_t* src, size_t maxCount)
+{
+ size_t converted = 0;
+ return wcstombs_s(&converted, buffer, src, maxCount);
+}
+#endif
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+#endif //USE_OPTICK \ No newline at end of file