Merge pull request #20 from MikePopoloski/master

Adding WinRT platform to bx
This commit is contained in:
Branimir Karadžić
2014-08-04 20:19:51 -07:00
9 changed files with 52 additions and 25 deletions

View File

@@ -62,6 +62,8 @@ namespace bx
{
#if BX_PLATFORM_XBOX360
__lwsync();
#elif BX_PLATFORM_WINRT
MemoryBarrier();
#elif BX_COMPILER_MSVC
_mm_mfence();
#else

View File

@@ -10,7 +10,7 @@
#if BX_PLATFORM_ANDROID
# include <android/log.h>
#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__)

View File

@@ -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

View File

@@ -14,13 +14,13 @@
#if BX_PLATFORM_NACL || BX_PLATFORM_LINUX || BX_PLATFORM_ANDROID || BX_PLATFORM_OSX
# include <pthread.h>
#elif BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360
#elif BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_WINRT
# include <errno.h>
#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;
}

View File

@@ -8,7 +8,7 @@
#include "bx.h"
#if BX_PLATFORM_WINDOWS
#if BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT
# include <windows.h>
#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);

View File

@@ -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

View File

@@ -16,7 +16,7 @@
# include <semaphore.h>
# include <time.h>
# include <pthread.h>
#elif BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360
#elif BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_WINRT
# include <windows.h>
# include <limits.h>
#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
{

View File

@@ -14,7 +14,7 @@
# include <emscripten.h>
#elif BX_PLATFORM_FREEBSD || BX_PLATFORM_LINUX || BX_PLATFORM_NACL || BX_PLATFORM_OSX || BX_PLATFORM_IOS || BX_PLATFORM_QNX
# include <sys/time.h> // gettimeofday
#elif BX_PLATFORM_WINDOWS
#elif BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT
# include <windows.h>
#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;

View File

@@ -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> // math.h is included because VS bitches:
// warning C4985: 'ceil': attributes not present on previous declaration.
// must be included before intrin.h.