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 fc1747e..3aa481f 100644 --- a/include/bx/macros.h +++ b/include/bx/macros.h @@ -171,7 +171,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 9f412c7..4ab5c2b 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_ANDROID \ || BX_PLATFORM_EMSCRIPTEN \ @@ -52,6 +52,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}; @@ -65,6 +68,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_ @@ -92,7 +97,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 @@ -104,7 +109,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); @@ -115,7 +120,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 @@ -127,6 +132,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_ @@ -136,6 +143,8 @@ namespace bx { #if BX_PLATFORM_WINDOWS ::SetEnvironmentVariableA(_name, NULL); +#elif BX_PLATFORM_WINRT + BX_UNUSED(_name); #else ::unsetenv(_name); #endif // BX_PLATFORM_ @@ -143,7 +152,9 @@ namespace bx inline int chdir(const char* _path) { -#if BX_COMPILER_MSVC +#if BX_PLATFORM_WINRT + BX_UNUSED(_path); +#elif BX_COMPILER_MSVC return ::_chdir(_path); #else return ::chdir(_path); @@ -152,7 +163,9 @@ namespace bx inline char* pwd(char* _buffer, uint32_t _size) { -#if BX_COMPILER_MSVC +#if BX_PLATFORM_WINRT + BX_UNUSED(_buffer, _size); +#elif BX_COMPILER_MSVC return ::_getcwd(_buffer, (int)_size); #else return ::getcwd(_buffer, _size); diff --git a/include/bx/platform.h b/include/bx/platform.h index a2eb196..bb88ca5 100644 --- a/include/bx/platform.h +++ b/include/bx/platform.h @@ -19,6 +19,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 @@ -53,14 +54,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 @@ -103,7 +109,7 @@ ) // 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 @@ -171,6 +177,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 71603a7..2efb8ac 100644 --- a/include/bx/timer.h +++ b/include/bx/timer.h @@ -14,7 +14,7 @@ # include #elif BX_PLATFORM_FREEBSD || BX_PLATFORM_LINUX || BX_PLATFORM_NACL || 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 f4a65b4..7bacfc5 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.