From d78317847dd4c565c21ff2ec01d9bc247982aae3 Mon Sep 17 00:00:00 2001 From: sephiroth99 Date: Wed, 20 Jan 2016 09:35:27 -0500 Subject: [PATCH 1/8] Fix link error when profiling is disabled These four functions are needed by microprofile even when profiling is disabled. --- src/xenia/base/profiling.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/xenia/base/profiling.cc b/src/xenia/base/profiling.cc index 96f2ff4b4..b078e18a9 100644 --- a/src/xenia/base/profiling.cc +++ b/src/xenia/base/profiling.cc @@ -272,8 +272,6 @@ void Profiler::Present() {} } // namespace xe -#if XE_OPTION_PROFILING - uint32_t MicroProfileGpuInsertTimeStamp() { return 0; } uint64_t MicroProfileGpuGetTimeStamp(uint32_t nKey) { return 0; } @@ -282,6 +280,7 @@ uint64_t MicroProfileTicksPerSecondGpu() { return 0; } const char* MicroProfileGetThreadName() { return "TODO: get thread name!"; } +#if XE_OPTION_PROFILING #if XE_OPTION_PROFILING_UI void MicroProfileDrawBox(int nX, int nY, int nX1, int nY1, uint32_t nColor, From 4c0f9e6342eee46224269e2001550396eec4c259 Mon Sep 17 00:00:00 2001 From: sephiroth99 Date: Wed, 20 Jan 2016 10:36:01 -0500 Subject: [PATCH 2/8] Add missing includes --- src/xenia/cpu/backend/x64/x64_emitter.cc | 1 + src/xenia/cpu/testing/vector_max_test.cc | 1 + src/xenia/cpu/testing/vector_min_test.cc | 1 + 3 files changed, 3 insertions(+) diff --git a/src/xenia/cpu/backend/x64/x64_emitter.cc b/src/xenia/cpu/backend/x64/x64_emitter.cc index 0feb06471..79f7f1cbd 100644 --- a/src/xenia/cpu/backend/x64/x64_emitter.cc +++ b/src/xenia/cpu/backend/x64/x64_emitter.cc @@ -11,6 +11,7 @@ #include +#include #include #include "xenia/base/assert.h" diff --git a/src/xenia/cpu/testing/vector_max_test.cc b/src/xenia/cpu/testing/vector_max_test.cc index 3b4bcd66c..eba85a653 100644 --- a/src/xenia/cpu/testing/vector_max_test.cc +++ b/src/xenia/cpu/testing/vector_max_test.cc @@ -10,6 +10,7 @@ #include "xenia/cpu/testing/util.h" #include +#include using namespace xe; using namespace xe::cpu; diff --git a/src/xenia/cpu/testing/vector_min_test.cc b/src/xenia/cpu/testing/vector_min_test.cc index 3d2b77190..6d54c3ef7 100644 --- a/src/xenia/cpu/testing/vector_min_test.cc +++ b/src/xenia/cpu/testing/vector_min_test.cc @@ -10,6 +10,7 @@ #include "xenia/cpu/testing/util.h" #include +#include using namespace xe; using namespace xe::cpu; From 1c149647391bf73f0ae206971ff92d100197788f Mon Sep 17 00:00:00 2001 From: sephiroth99 Date: Wed, 20 Jan 2016 10:57:50 -0500 Subject: [PATCH 3/8] Add missing override on virtual function --- src/xenia/gpu/gl4/gl4_shader.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xenia/gpu/gl4/gl4_shader.h b/src/xenia/gpu/gl4/gl4_shader.h index 96a62f718..91b1e6098 100644 --- a/src/xenia/gpu/gl4/gl4_shader.h +++ b/src/xenia/gpu/gl4/gl4_shader.h @@ -29,7 +29,7 @@ class GL4Shader : public Shader { GLuint shader() const { return shader_; } GLuint vao() const { return vao_; } - bool Prepare(); + bool Prepare() override; protected: bool PrepareVertexArrayObject(); From 5d9a4b683078062801136b618fe0310d0832e39e Mon Sep 17 00:00:00 2001 From: sephiroth99 Date: Wed, 20 Jan 2016 11:00:37 -0500 Subject: [PATCH 4/8] Handle all other cases in switch statements --- src/xenia/cpu/hir/value.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/xenia/cpu/hir/value.cc b/src/xenia/cpu/hir/value.cc index 4d30de853..0c6f62f55 100644 --- a/src/xenia/cpu/hir/value.cc +++ b/src/xenia/cpu/hir/value.cc @@ -251,6 +251,9 @@ void Value::Round(RoundMode round_mode) { case ROUND_TO_NEAREST: constant.f32 = std::round(constant.f32); return; + default: + assert_unhandled_case(round_mode); + return; } return; case FLOAT64_TYPE: @@ -261,11 +264,15 @@ void Value::Round(RoundMode round_mode) { case ROUND_TO_NEAREST: constant.v128.f32[i] = std::round(constant.v128.f32[i]); return; + default: + assert_unhandled_case(round_mode); + return; } } return; default: assert_unhandled_case(type); + return; } } @@ -791,6 +798,9 @@ void Value::Extract(Value* vec, Value* index) { case INT64_TYPE: constant.u64 = vec->constant.v128.u64[index->constant.u64]; break; + default: + assert_unhandled_case(type); + break; } } @@ -1013,6 +1023,9 @@ void Value::VectorSub(Value* other, TypeName type, bool is_unsigned, } } } + default: + assert_unhandled_case(type); + break; } } From f17b80c61e6a8a44bebdb60dfac6bff4b8989860 Mon Sep 17 00:00:00 2001 From: sephiroth99 Date: Wed, 20 Jan 2016 11:04:28 -0500 Subject: [PATCH 5/8] Use stdlib 'hardware_concurrency' to get logical processor count This has the benifit of being multiplatform. --- src/xenia/base/threading.cc | 8 ++++++++ src/xenia/base/threading_win.cc | 10 ---------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/xenia/base/threading.cc b/src/xenia/base/threading.cc index 40d89a6c0..98c91715e 100644 --- a/src/xenia/base/threading.cc +++ b/src/xenia/base/threading.cc @@ -12,6 +12,14 @@ namespace xe { namespace threading { +uint32_t logical_processor_count() { + static uint32_t value = 0; + if (!value) { + value = std::thread::hardware_concurrency(); + } + return value; +} + thread_local uint32_t current_thread_id_ = UINT_MAX; uint32_t current_thread_id() { diff --git a/src/xenia/base/threading_win.cc b/src/xenia/base/threading_win.cc index d36ee76e1..4381db8cb 100644 --- a/src/xenia/base/threading_win.cc +++ b/src/xenia/base/threading_win.cc @@ -16,16 +16,6 @@ namespace xe { namespace threading { -uint32_t logical_processor_count() { - static uint32_t value = 0; - if (!value) { - SYSTEM_INFO system_info; - GetSystemInfo(&system_info); - value = system_info.dwNumberOfProcessors; - } - return value; -} - void EnableAffinityConfiguration() { HANDLE process_handle = GetCurrentProcess(); DWORD_PTR process_affinity_mask; From 204e885d3dbe7d52d5a30aedd4d5e7e24e84ba41 Mon Sep 17 00:00:00 2001 From: sephiroth99 Date: Wed, 20 Jan 2016 11:09:45 -0500 Subject: [PATCH 6/8] Add 'posix' as a platform suffix --- tools/build/scripts/build_paths.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/build/scripts/build_paths.lua b/tools/build/scripts/build_paths.lua index 2e5231844..5fcceb061 100644 --- a/tools/build/scripts/build_paths.lua +++ b/tools/build/scripts/build_paths.lua @@ -7,4 +7,8 @@ build_tools = "tools/build" build_scripts = build_tools .. "/scripts" build_tools_src = build_tools .. "/src" -platform_suffix = "win" +if os.is("windows") then + platform_suffix = "win" +else + platform_suffix = "posix" +end From bf910c2d9a11a3ab384a27dd3c46783272fa7380 Mon Sep 17 00:00:00 2001 From: sephiroth99 Date: Wed, 20 Jan 2016 11:26:35 -0500 Subject: [PATCH 7/8] Add missing definitions for XAPC constants Fixes linking errors for these symbols. --- src/xenia/kernel/xthread.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/xenia/kernel/xthread.cc b/src/xenia/kernel/xthread.cc index da009c69d..81d11fa7f 100644 --- a/src/xenia/kernel/xthread.cc +++ b/src/xenia/kernel/xthread.cc @@ -36,6 +36,10 @@ DEFINE_bool(ignore_thread_affinities, true, namespace xe { namespace kernel { +const uint32_t XAPC::kSize; +const uint32_t XAPC::kDummyKernelRoutine; +const uint32_t XAPC::kDummyRundownRoutine; + using xe::cpu::ppc::PPCOpcode; uint32_t next_xthread_id_ = 0; From a74c88851b49608335907a3ae7a19c5ff1aed3f7 Mon Sep 17 00:00:00 2001 From: sephiroth99 Date: Wed, 20 Jan 2016 11:41:33 -0500 Subject: [PATCH 8/8] Rework RtlTime with portable time conversion functions --- src/xenia/kernel/xboxkrnl/xboxkrnl_rtl.cc | 55 +++++++++++------------ 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/src/xenia/kernel/xboxkrnl/xboxkrnl_rtl.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_rtl.cc index c019d3394..2ee1412ad 100644 --- a/src/xenia/kernel/xboxkrnl/xboxkrnl_rtl.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_rtl.cc @@ -25,8 +25,10 @@ #include "xenia/kernel/xevent.h" #include "xenia/kernel/xthread.h" -// For FileTimeToSystemTime and SystemTimeToFileTime: +#if XE_PLATFORM_WIN32 #include "xenia/base/platform_win.h" +#define timegm _mkgmtime +#endif namespace xe { namespace kernel { @@ -439,44 +441,41 @@ struct X_TIME_FIELDS { }; static_assert(sizeof(X_TIME_FIELDS) == 16, "Must be LARGEINTEGER"); +// https://support.microsoft.com/en-us/kb/167296 void RtlTimeToTimeFields(lpqword_t time_ptr, pointer_t time_fields_ptr) { - // TODO(benvanik): replace with our own version. - FILETIME ft; - ft.dwHighDateTime = static_cast(time_ptr.value() >> 32); - ft.dwLowDateTime = static_cast(time_ptr.value()); - SYSTEMTIME st; - FileTimeToSystemTime(&ft, &st); + int64_t time_ms = time_ptr.value() / 10000 - 11644473600000LL; + time_t timet = time_ms / 1000; + struct tm* tm = gmtime(&timet); - time_fields_ptr->year = st.wYear; - time_fields_ptr->month = st.wMonth; - time_fields_ptr->day = st.wDay; - time_fields_ptr->hour = st.wHour; - time_fields_ptr->minute = st.wMinute; - time_fields_ptr->second = st.wSecond; - time_fields_ptr->milliseconds = st.wMilliseconds; - time_fields_ptr->weekday = st.wDayOfWeek; + time_fields_ptr->year = tm->tm_year + 1900; + time_fields_ptr->month = tm->tm_mon + 1; + time_fields_ptr->day = tm->tm_mday; + time_fields_ptr->hour = tm->tm_hour; + time_fields_ptr->minute = tm->tm_min; + time_fields_ptr->second = tm->tm_sec; + time_fields_ptr->milliseconds = time_ms % 1000; + time_fields_ptr->weekday = tm->tm_wday; } DECLARE_XBOXKRNL_EXPORT(RtlTimeToTimeFields, ExportTag::kImplemented); dword_result_t RtlTimeFieldsToTime(pointer_t time_fields_ptr, lpqword_t time_ptr) { - // TODO(benvanik): replace with our own version. - SYSTEMTIME st; - st.wYear = time_fields_ptr->year; - st.wMonth = time_fields_ptr->month; - st.wDay = time_fields_ptr->day; - st.wHour = time_fields_ptr->hour; - st.wMinute = time_fields_ptr->minute; - st.wSecond = time_fields_ptr->second; - st.wMilliseconds = time_fields_ptr->milliseconds; - st.wDayOfWeek = time_fields_ptr->weekday; - FILETIME ft; - if (!SystemTimeToFileTime(&st, &ft)) { + struct tm tm; + tm.tm_year = time_fields_ptr->year - 1900; + tm.tm_mon = time_fields_ptr->month - 1; + tm.tm_mday = time_fields_ptr->day; + tm.tm_hour = time_fields_ptr->hour; + tm.tm_min = time_fields_ptr->minute; + tm.tm_sec = time_fields_ptr->second; + tm.tm_isdst = 0; + time_t timet = timegm(&tm); + if (timet == -1) { // set last error = ERROR_INVALID_PARAMETER return 0; } - uint64_t time = (uint64_t(ft.dwHighDateTime) << 32) | ft.dwLowDateTime; + uint64_t time = + ((timet + 11644473600LL) * 1000 + time_fields_ptr->milliseconds) * 10000; *time_ptr = time; return 1; }