From 7fdfdb38f0530d86caec6d875b854c11216c2d72 Mon Sep 17 00:00:00 2001 From: Mike Popoloski Date: Tue, 24 Jun 2014 20:24:21 -0700 Subject: [PATCH] Adding WINRT platform support to bx. --- include/bx/cpu.h | 2 ++ include/bx/debug.h | 4 ++-- include/bx/macros.h | 2 +- include/bx/mutex.h | 8 ++++++-- include/bx/os.h | 17 +++++++++++++---- include/bx/platform.h | 24 ++++++++++++++++-------- include/bx/sem.h | 4 ++-- include/bx/timer.h | 6 +++--- include/bx/uint32_t.h | 2 +- 9 files changed, 46 insertions(+), 23 deletions(-) diff --git a/include/bx/cpu.h b/include/bx/cpu.h index 70379ec..483d935 100644 --- a/include/bx/cpu.h +++ b/include/bx/cpu.h @@ -62,6 +62,8 @@ namespace bx { #if BX_PLATFORM_XBOX360 __lwsync(); +#elif BX_PLATFORM_WINRT + MemoryBarrier(); #elif BX_COMPILER_MSVC _mm_mfence(); #else diff --git a/include/bx/debug.h b/include/bx/debug.h index 2f58bbd..6a87c14 100644 --- a/include/bx/debug.h +++ b/include/bx/debug.h @@ -10,7 +10,7 @@ #if BX_PLATFORM_ANDROID # include -#elif BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 +#elif BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_WINRT extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char* _str); #elif BX_PLATFORM_IOS || BX_PLATFORM_OSX # if defined(__OBJC__) @@ -47,7 +47,7 @@ namespace bx { #if BX_PLATFORM_ANDROID __android_log_write(ANDROID_LOG_DEBUG, "", _out); -#elif BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 +#elif BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_WINRT OutputDebugStringA(_out); #elif BX_PLATFORM_IOS || BX_PLATFORM_OSX # if defined(__OBJC__) diff --git a/include/bx/macros.h b/include/bx/macros.h index f3dedb3..cee296d 100644 --- a/include/bx/macros.h +++ b/include/bx/macros.h @@ -170,7 +170,7 @@ #endif // BX_CONFIG_SEMAPHORE_PTHREAD #ifndef BX_CONFIG_SUPPORTS_THREADING -# define BX_CONFIG_SUPPORTS_THREADING !BX_PLATFORM_EMSCRIPTEN +# define BX_CONFIG_SUPPORTS_THREADING !(BX_PLATFORM_EMSCRIPTEN || BX_PLATFORM_WINRT) #endif // BX_CONFIG_SUPPORTS_THREADING #endif // BX_MACROS_H_HEADER_GUARD diff --git a/include/bx/mutex.h b/include/bx/mutex.h index 903babd..bb09059 100644 --- a/include/bx/mutex.h +++ b/include/bx/mutex.h @@ -14,13 +14,13 @@ #if BX_PLATFORM_NACL || BX_PLATFORM_LINUX || BX_PLATFORM_ANDROID || BX_PLATFORM_OSX # include -#elif BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 +#elif BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_WINRT # include #endif // BX_PLATFORM_ namespace bx { -#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 +#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_WINRT typedef CRITICAL_SECTION pthread_mutex_t; typedef unsigned pthread_mutexattr_t; @@ -43,7 +43,11 @@ namespace bx inline int pthread_mutex_init(pthread_mutex_t* _mutex, pthread_mutexattr_t* /*_attr*/) { +#if BX_PLATFORM_WINRT + InitializeCriticalSectionEx(_mutex, 4000, 0); // docs recommend 4000 spincount as sane default +#else InitializeCriticalSection(_mutex); +#endif return 0; } diff --git a/include/bx/os.h b/include/bx/os.h index 5c4a694..57112a9 100644 --- a/include/bx/os.h +++ b/include/bx/os.h @@ -8,7 +8,7 @@ #include "bx.h" -#if BX_PLATFORM_WINDOWS +#if BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT # include #elif BX_PLATFORM_NACL \ || BX_PLATFORM_ANDROID \ @@ -45,6 +45,9 @@ namespace bx { #if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 ::Sleep(_ms); +#elif BX_PLATFORM_WINRT + BX_UNUSED(_ms); + debugOutput("sleep is not implemented"); debugBreak(); #else timespec req = {(time_t)_ms/1000, (long)((_ms%1000)*1000000)}; timespec rem = {0, 0}; @@ -58,6 +61,8 @@ namespace bx ::SwitchToThread(); #elif BX_PLATFORM_XBOX360 ::Sleep(0); +#elif BX_PLATFORM_WINRT + debugOutput("yield is not implemented"); debugBreak(); #else ::sched_yield(); #endif // BX_PLATFORM_ @@ -85,7 +90,7 @@ namespace bx { #if BX_PLATFORM_WINDOWS return (void*)::LoadLibraryA(_filePath); -#elif BX_PLATFORM_NACL || BX_PLATFORM_EMSCRIPTEN +#elif BX_PLATFORM_NACL || BX_PLATFORM_EMSCRIPTEN || BX_PLATFORM_WINRT BX_UNUSED(_filePath); return NULL; #else @@ -97,7 +102,7 @@ namespace bx { #if BX_PLATFORM_WINDOWS ::FreeLibrary( (HMODULE)_handle); -#elif BX_PLATFORM_NACL || BX_PLATFORM_EMSCRIPTEN +#elif BX_PLATFORM_NACL || BX_PLATFORM_EMSCRIPTEN || BX_PLATFORM_WINRT BX_UNUSED(_handle); #else ::dlclose(_handle); @@ -108,7 +113,7 @@ namespace bx { #if BX_PLATFORM_WINDOWS return (void*)::GetProcAddress( (HMODULE)_handle, _symbol); -#elif BX_PLATFORM_NACL || BX_PLATFORM_EMSCRIPTEN +#elif BX_PLATFORM_NACL || BX_PLATFORM_EMSCRIPTEN || BX_PLATFORM_WINRT BX_UNUSED(_handle, _symbol); return NULL; #else @@ -120,6 +125,8 @@ namespace bx { #if BX_PLATFORM_WINDOWS ::SetEnvironmentVariableA(_name, _value); +#elif BX_PLATFORM_WINRT + BX_UNUSED(_name, _value); #else ::setenv(_name, _value, 1); #endif // BX_PLATFORM_ @@ -129,6 +136,8 @@ namespace bx { #if BX_PLATFORM_WINDOWS ::SetEnvironmentVariableA(_name, NULL); +#elif BX_PLATFORM_WINRT + BX_UNUSED(_name); #else ::unsetenv(_name); #endif // BX_PLATFORM_ diff --git a/include/bx/platform.h b/include/bx/platform.h index 81833f4..86eb211 100644 --- a/include/bx/platform.h +++ b/include/bx/platform.h @@ -18,6 +18,7 @@ #define BX_PLATFORM_OSX 0 #define BX_PLATFORM_QNX 0 #define BX_PLATFORM_WINDOWS 0 +#define BX_PLATFORM_WINRT 0 #define BX_PLATFORM_XBOX360 0 #define BX_CPU_ARM 0 @@ -52,14 +53,19 @@ # undef BX_PLATFORM_XBOX360 # define BX_PLATFORM_XBOX360 1 #elif defined(_WIN32) || defined(_WIN64) -# undef BX_PLATFORM_WINDOWS // http://msdn.microsoft.com/en-us/library/6sehtctf.aspx -# if !defined(WINVER) && !defined(_WIN32_WINNT) -// Windows Server 2003 with SP1, Windows XP with SP2 and above -# define WINVER 0x0502 -# define _WIN32_WINNT 0x0502 -# endif // !defined(WINVER) && !defined(_WIN32_WINNT) -# define BX_PLATFORM_WINDOWS _WIN32_WINNT +# if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP) +# undef BX_PLATFORM_WINDOWS +# if !defined(WINVER) && !defined(_WIN32_WINNT) + // Windows Server 2003 with SP1, Windows XP with SP2 and above +# define WINVER 0x0502 +# define _WIN32_WINNT 0x0502 +# endif // !defined(WINVER) && !defined(_WIN32_WINNT) +# define BX_PLATFORM_WINDOWS _WIN32_WINNT +# else +# undef BX_PLATFORM_WINRT +# define BX_PLATFORM_WINRT 1 +# endif #elif defined(__native_client__) // NaCl compiler defines __linux__ # undef BX_PLATFORM_NACL @@ -96,7 +102,7 @@ || BX_PLATFORM_QNX) // http://sourceforge.net/apps/mediawiki/predef/index.php?title=Architectures -#if defined(__arm__) +#if defined(__arm__) || (defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)) # undef BX_CPU_ARM # define BX_CPU_ARM 1 # define BX_CACHE_LINE_SIZE 64 @@ -162,6 +168,8 @@ # define BX_PLATFORM_NAME "QNX" #elif BX_PLATFORM_WINDOWS # define BX_PLATFORM_NAME "Windows" +#elif BX_PLATFORM_WINRT +# define BX_PLATFORM_NAME "WinRT" #endif // BX_PLATFORM_ #if BX_CPU_ARM diff --git a/include/bx/sem.h b/include/bx/sem.h index 50e150b..dcfe654 100644 --- a/include/bx/sem.h +++ b/include/bx/sem.h @@ -16,7 +16,7 @@ # include # include # include -#elif BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 +#elif BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_WINRT # include # include #endif // BX_PLATFORM_ @@ -190,7 +190,7 @@ namespace bx }; # endif // BX_CONFIG_SEMAPHORE_PTHREAD -#elif BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 +#elif BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_WINRT class Semaphore { diff --git a/include/bx/timer.h b/include/bx/timer.h index ae52038..769cd9d 100644 --- a/include/bx/timer.h +++ b/include/bx/timer.h @@ -14,7 +14,7 @@ # include #elif BX_PLATFORM_NACL || BX_PLATFORM_LINUX || BX_PLATFORM_OSX || BX_PLATFORM_IOS || BX_PLATFORM_QNX # include // gettimeofday -#elif BX_PLATFORM_WINDOWS +#elif BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT # include #endif // BX_PLATFORM_ @@ -22,7 +22,7 @@ namespace bx { inline int64_t getHPCounter() { -#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 +#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_WINRT LARGE_INTEGER li; // Performance counter value may unexpectedly leap forward // http://support.microsoft.com/kb/274323 @@ -44,7 +44,7 @@ namespace bx inline int64_t getHPFrequency() { -#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 +#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_WINRT LARGE_INTEGER li; QueryPerformanceFrequency(&li); return li.QuadPart; diff --git a/include/bx/uint32_t.h b/include/bx/uint32_t.h index f06d1b0..267d296 100644 --- a/include/bx/uint32_t.h +++ b/include/bx/uint32_t.h @@ -29,7 +29,7 @@ #include "bx.h" #if BX_COMPILER_MSVC -# if BX_PLATFORM_WINDOWS +# if BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT # include // math.h is included because VS bitches: // warning C4985: 'ceil': attributes not present on previous declaration. // must be included before intrin.h.