From d4bb05ae25943ae04e321f2c66bc5ab4f4fd911c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos=20Tur=C3=A1nszki?= Date: Wed, 14 Jan 2026 17:32:44 +0100 Subject: [PATCH] apple platform improvements --- WickedEngine/wiJobSystem.cpp | 19 +++++++++++++++++++ WickedEngine/wiPlatform.h | 2 +- WickedEngine/wiSpinLock.h | 20 +++++++++++++------- WickedEngine/wiVersion.cpp | 2 +- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/WickedEngine/wiJobSystem.cpp b/WickedEngine/wiJobSystem.cpp index ce032d0bd..440c85065 100644 --- a/WickedEngine/wiJobSystem.cpp +++ b/WickedEngine/wiJobSystem.cpp @@ -28,6 +28,10 @@ #include "wiJobSystem_PS5.h" #endif // PLATFORM_PS5 +#ifdef __APPLE__ +#include +#endif // __APPLE__ + namespace wi::jobsystem { struct alignas(64) Job @@ -306,6 +310,21 @@ namespace wi::jobsystem default: assert(0); } +#elif defined(__APPLE__) + switch (priority) + { + case Priority::High: + pthread_set_qos_class_self_np(QOS_CLASS_USER_INTERACTIVE, 0); + break; + case Priority::Low: + pthread_set_qos_class_self_np(QOS_CLASS_UTILITY, 0); + break; + case Priority::Streaming: + pthread_set_qos_class_self_np(QOS_CLASS_BACKGROUND, 0); + break; + default: + assert(0); + } #endif // PLATFORM_LINUX while (internal_state.alive.load(std::memory_order_relaxed)) diff --git a/WickedEngine/wiPlatform.h b/WickedEngine/wiPlatform.h index 25242f1f0..9cd659b8d 100644 --- a/WickedEngine/wiPlatform.h +++ b/WickedEngine/wiPlatform.h @@ -71,7 +71,7 @@ namespace wi::platform SDL_Event quit_event; quit_event.type = SDL_QUIT; SDL_PushEvent(&quit_event); -#else +#elif defined(__APPLE__) std::exit(0); #endif diff --git a/WickedEngine/wiSpinLock.h b/WickedEngine/wiSpinLock.h index e0cf3119b..40f4c5d7f 100644 --- a/WickedEngine/wiSpinLock.h +++ b/WickedEngine/wiSpinLock.h @@ -3,16 +3,17 @@ #include #if defined(_M_ARM64) || defined(__arm64__) -#include +#ifdef _WIN32 +#include // __yield() +#else +#include // __yield() +#endif // _WIN32 #else #include // _mm_pause() #endif // efined(_M_ARM64) || defined(__arm64__) namespace wi { -#if defined(_M_ARM64) || defined(__arm64__) - using SpinLock = std::mutex; -#else class SpinLock { private: @@ -25,11 +26,17 @@ namespace wi { if (spin < 10) { - _mm_pause(); // SMT thread swap can occur here + // SMT thread swap can occur here: +#if defined(_M_ARM64) || defined(__arm64__) + __yield(); +#else + _mm_pause(); +#endif // defined(_M_ARM64) || defined(__arm64__) } else { - std::this_thread::yield(); // OS thread swap can occur here. It is important to keep it as fallback, to avoid any chance of lockup by busy wait + // OS thread swap can occur here. It is important to keep it as fallback, to avoid any chance of lockup by busy wait + std::this_thread::yield(); } spin++; } @@ -44,5 +51,4 @@ namespace wi lck.clear(std::memory_order_release); } }; -#endif // efined(_M_ARM64) || defined(__arm64__) } diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 0c82f360d..e5fa54069 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wi::version // minor features, major updates, breaking compatibility changes const int minor = 72; // minor bug fixes, alterations, refactors, updates - const int revision = 2; + const int revision = 3; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);