Repository navigation
Feat(Platform): add macOS support, CI workflow, and packaging - #469
Incognito-Coder wants to merge 23 commits into
Conversation
- Add Darwin POSIX compatibility layer in src/compat_mac.h and runtime integration - Implement Mach VM low address space allocation and shm_open fallbacks in src/runtime_memory.c - Implement Darwin thread TCB mapping via pthread_setspecific in src/runtime_thread.c - Detect Rosetta 2 via sysctlbyname to validate CPU instruction extensions in src/cpu_check.c - Support Mach-O symbols, Darwin ucontext_t register access, and stack entry in src/probe.c - Adapt GPU core and shaders for Darwin frameworks (Metal, Foundation, QuartzCore) and Clang C++23 - Add Vulkan portability enumeration extension for MoltenVK compatibility - Update launcher, run.py, and run.sh with macOS paths, fonts, and MoltenVK ICD detection - Add packaging script (packaging/macos/package.sh) and GitHub Actions CI (.github/workflows/macos-zip.yml) - Update README.md with macOS requirements and instructions
…on errors - Enable -fexperimental-library compiler and linker flag on Apple Clang for C++20 jthread and stop_token support - Handle CMake policy CMP0167 for Boost - Force-include common/polyfill_thread.h in gpu/shim/gow3_mac_compat.h - Replace bare <thread>/<stop_token> includes with common/polyfill_thread.h in renderer/core headers - Disable unnecessary Homebrew auto-updates and upgrade recompiles in macOS CI workflow
|
Fix build errors on macOS CI (Intel runner / Apple Clang):
|
- Use bounded polling loops in tests/test_pad.c for short tap test - Update checkout and artifact actions to v5 in macOS CI workflow
- Recursively bundle all required Homebrew and non-system dylibs into bin/lib/ - Rewrite Mach-O install names and dependency paths to @rpath with install_name_tool - Add @loader_path/lib and @executable_path/lib to LC_RPATH - Ad-hoc codesign all bundled binaries and dylibs for Gatekeeper and Rosetta 2 - Pass env with DYLD search paths in run.py and run.sh
…r BDA on MoltenVK - Prioritize bundled x86_64 dylibs in bin/lib over host ARM64 Homebrew libraries during build - Auto-generate unversioned dylib symlinks in bin/lib and copy built artifacts to bin/ - Support SIGBUS in probe fault handler for GPU page tracking on Darwin/Rosetta 2 - Guard buffer device address assertion for sparse buffers on MoltenVK
|
Pushed commit
|
…mance overlay metrics - Fix host fault (signal 11) in copyBufferToBuffer by allocating dedicated DeviceLocal VMA buffers for sparse arenas and bypassing sparse queue binds on macOS - Fix SPIR-V to MSL conversion failure from multiple barycentric stage inputs by reusing bary_coord BuiltIn on Metal - Fix severe frame rate degradation (< 20 FPS) caused by texture cache thrashing on unified memory architectures by guarding total_used_memory against process-wide allocation accounting - Implement native macOS CPU, RAM, VRAM, and GPU utilization stats via getrusage, mach_task_basic_info, and IOKit IOAccelerator - Add MoltenVK performance flags for asynchronous queue submits, parallel shader compilation, and command buffer prefilling
|
Pushed commit
|
…educe thermals and VRAM usage - Audio: Eliminate audio pops and crackling by sizing stream queues to match CoreAudio hardware quanta (1024 frames) and removing destructive mid-stream silence injection - Audio Cadence: Replace imprecise nanosleep with mach_wait_until in runtime_audio.c for microsecond-precise return timing matching PS4 hardware - QoS & Thermals: Set QOS_CLASS_USER_INTERACTIVE on guest threads and map shadps4 ThreadPriority to Darwin QoS classes, ensuring game and audio threads schedule on P-cores - Lock Contention: Add adaptive spin-pause and sched_yield to compat_pthread_mutex_timedlock and rwlocks, preventing CPU spin-overheating and context switch overhead across 11M+ lock acquisitions - Metal Resource Optimization: Enable MVK_CONFIG_USE_MTLHEAP, MVK_CONFIG_PREALLOCATE_DESCRIPTORS, and MVK_CONFIG_TEXTURE_1D_AS_2D to pool allocations and reduce driver CPU/VRAM overhead
|
Pushed commit
|
# Conflicts: # gpu/shim/window.cpp # launcher/gow3_launcher_win.py
|
Synchronized branch with
|
…ir_lock, Darwin QoS, spinlock yielding, and single-sampled depth EN-US - Page Manager Lock: Replaced Darwin spinlock fallback with native os_unfair_lock in Common::AdaptiveMutex, eliminating priority inversion and core starvation between worker threads - Draw Preparation QoS: Switched Gow3Threads::MakeBackground() from PRIO_DARWIN_BG (which throttled DrawPrep and DrawScan threads to low-power E-cores at min clock frequency) to QOS_CLASS_UTILITY - SpinLock Yielding: Added adaptive yield backoff to Common::SpinLock to prevent CPU spinning starvation across high thread-count workloads - Guest Mutex Fast-Path: Added pthread_mutex_trylock fast-path with short spin-pause in mutex_lock to avoid millions of Mach kernel context switches - Single-Sample Depth Default: Defaulted GOW3_NO_MSAA=1 on macOS to eliminate MoltenVK mixed color/depth sample emulation overhead and halve unified memory bandwidth - MoltenVK Tuning: Enabled MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS, MVK_CONFIG_ALLOW_METAL_FENCES, and MVK_CONFIG_PRESENT_WITH_COMMAND_BUFFER - Build & Test Suite: Added loader rpaths and include paths to build.sh for macOS unit tests --- PT-BR - Bloqueio do Gerenciador de Páginas: Substituído o fallback de spinlock no Darwin pelo os_unfair_lock nativo no Common::AdaptiveMutex, eliminando inversão de prioridade e starvation - QoS de Preparação de Draw: Substituído PRIO_DARWIN_BG por QOS_CLASS_UTILITY no Gow3Threads::MakeBackground(), evitando que threads de DrawPrep fossem estranguladas nos E-cores - Yield em SpinLock: Adicionado recuo com yield adaptativo no Common::SpinLock para prevenir queima inútil de ciclos de CPU - Fast-Path de Mutex do Guest: Adicionado fast-path de trylock com pausa adaptativa para evitar milhões de trocas de contexto no kernel Mach - Depth com Sample Único por Padrão: GOW3_NO_MSAA=1 ativado por padrão no macOS para eliminar emulação de mixed samples no MoltenVK e reduzir largura de banda de memória unificada - Ajustes no MoltenVK: Ativados MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS, MVK_CONFIG_ALLOW_METAL_FENCES e MVK_CONFIG_PRESENT_WITH_COMMAND_BUFFER - Build e Testes: Corrigidos caminhos de rpath e includes no build.sh para testes unitários no macOS
🚀 Performance Optimization Update: Elimination of Apple Silicon M4 Frame Rate BottlenecksThis update resolves the low frame rate issue (< 20 FPS) on macOS Apple Silicon (M1/M2/M3/M4) systems: Key Enhancements & Root-Cause Fixes:
|
… and optimize threading - Fix MoltenVK pipeline creation failure (ErrorInitializationFailed) by setting pTessellationState to nullptr when no tessellation shader stages exist. - Add un-cached pipeline creation retry fallback, and do not abort with ASSERT_MSG on Apple platforms on pipeline failure. - Add null pipeline handle guards in vk_rasterizer DrawRecord, DispatchRecord, and DispatchIndirectRecord to gracefully skip invalid draws. - Fix GetInstanceLayers false error when Vulkan instance layer list is empty. - Demote unavailable optional extensions, unsupported format capability queries, denorm flushing, and unimplemented predication warnings to info/debug level. - Replace Common::SpinLock on macOS with native os_unfair_lock to eliminate CPU spinning and thermal throttling under Rosetta 2. - Clamp draw preparation workers to 2-4 and shorten spin-wait loops in vk_scheduler, vk_draw_pipe, and vk_bind_helper. - Accelerate video decoder with FFmpeg multi-threading (thread_count=4, frame+slice) and bulk contiguous memory copies for luma/chroma planes. - Enable AVX, SSE4.2, BMI1, and LZCNT vectorization with -O3 for Darwin host compilation.
🛠️ Update: MoltenVK Pipeline Stability, Cutscene Acceleration, and Rosetta 2 Thermal FixesThis update resolves the GPU graphics pipeline assertion failure on save load/stage transition, accelerates video cutscenes, and suppresses spurious GPU errors and warnings: 1. MoltenVK Pipeline Creation Crash Fix (
|
…ream v2.5.0 updates for higher FPS under Rosetta 2 - Integrated third_party/mimalloc with macOS zone interposing (MI_OSX_ZONE=1, MI_OSX_INTERPOSE=1) to eliminate szone_malloc global lock contention across worker threads under Rosetta 2 JIT memory fences. - Injected libmimalloc.dylib via DYLD_INSERT_LIBRARIES in run.sh and run.py; added bundle packaging in package.sh. - Enabled hardware Flush-To-Zero (FTZ) and Denormals-Are-Zero (DAZ) via SSE MXCSR register in probe.c and runtime_thread.c host thread worker creation to eliminate Rosetta 2 subnormal floating-point software traps during matrix and physics calculations. - Configured Clang vectorization flags -fno-math-errno -fno-trapping-math on Darwin in build.sh and gpu/CMakeLists.txt to emit direct x86 SSE/AVX instructions without math errno calls. - Tuned MoltenVK command buffer prefill (MVK_CONFIG_PREFILL_METAL_COMMAND_BUFFERS=3) and queue pool capacity (MVK_CONFIG_MAX_ACTIVE_METAL_COMMAND_BUFFERS_PER_QUEUE=64) to reduce Metal encoding latency.
🚀 Update: Upstream Synchronization & Rosetta 2 Emulation Performance EnhancementsThis update merges the latest changes from 1. Upstream Merge & Conflict Resolution
2. High-Performance
|
…LIBRARIES to probe - Compiled libmimalloc.dylib as a universal binary (-arch x86_64 -arch arm64) so it can be loaded cleanly regardless of host or guest process architecture. - Removed DYLD_INSERT_LIBRARIES export from run.sh to avoid injecting mimalloc into the parent shell and arm64 Python. - Isolated DYLD_INSERT_LIBRARIES in run.py: stripped it from os.environ for Python child utility scripts, added Mach-O header architecture checks (fat / thin 64-bit), and only set it in env for the probe emulator process. - Added settings.json to .gitignore.
🩹 Fix: Universal
|
…ltenVK prefill - Removed mimalloc interposing: Rosetta 2 cross-thread allocations between guest workers, draw prep workers, and Apple Metal driver threads caused severe atomic CAS lock contention and cache-line false sharing on Apple Silicon. Restored Apple's native libsystem_malloc which is tuned for M-series unified memory. - Reverted MoltenVK command buffer prefill to default (1) and removed queue buffer overrides: MVK_CONFIG_PREFILL_METAL_COMMAND_BUFFERS=3 forced per-command encoding and continuous autorelease pool drains on every single draw call, heavily degrading frame pacing. - Reverted SSE MXCSR FTZ/DAZ overrides in probe.c and runtime_thread.c: flushing denormals to zero caused precision drops and physics/matrix recalculations in the guest engine. - Reverted -fno-math-errno -fno-trapping-math in gpu/CMakeLists.txt and build.sh to prevent miscompilation of IEEE 754 isnan/isinf checks in the shader recompiler.
⚡ Performance Fix: Restored Native Memory Management & Command PrefillFollowing in-game profiling on Apple Silicon laptops, we reverted the experimental allocator and compiler fast-math overrides that introduced frame drops:
|
|
EN-US
Thank you for your contribution! Closing in favor of #798. PT-BR
Obrigado pela contribuição! Encerrada em favor da #798. |
Summary
This PR adds macOS support to God of War III Remastered source port / hybrid loader, running natively on Intel x86-64 Macs and under Rosetta 2 on Apple Silicon Macs (M1/M2/M3/M4) with Metal-accelerated Vulkan (via MoltenVK).
Key Architectural & Code Changes
Darwin POSIX Compatibility Layer (
src/compat_mac.h):compat_pthread_mutex_timedlock,compat_pthread_rwlock_timedrdlock, andcompat_pthread_rwlock_timedwrlock.compat_clock_nanosleepusingpthread_cond_timedwait.getrandom()witharc4random_buf().pthread_barrier_temulation.timespecstat fields (st_atim->st_atimespec).Low-Memory Address Space & Shared Memory (
src/runtime_memory.c):runtime_low_mapusing Mach VMmach_vm_allocate(..., VM_FLAGS_FIXED)for PS4 guest address space (< 1 TiB).memfd_createwith POSIXshm_open+ftruncate+mmap(MAP_SHARED).TCB Offset & Rosetta 2 Support (
src/runtime_thread.c,src/cpu_check.c):pthread_key_createandpthread_setspecific(Darwin x86_64 stores key slots at%gs:(key * 8)).sysctlbyname("sysctl.proc_translated", &translated, ...)to ensure AVX, BMI1, MOVBE, and LZCNT feature flags pass (Rosetta 2 masks AVX in CPUID leaf 1 despite executing it).Loader & Signals (
src/probe.c):_enter_on_stack.patch_tcb_loads()on macOS.ucontext_tthread register state (uc_mcontext->__ss).GPU Emulation Core (
gpu/):Metal,Foundation, andQuartzCoreframework linkages.VulkanMemoryAllocator.PRIO_DARWIN_THREAD) and thread ID retrieval (pthread_threadid_np).pm4_cmds.h..section __TEXT,__constin overlay font embedding.Vulkan / MoltenVK Compatibility:
VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAMEacross runtime and tools.run.sh.CI/CD Workflow & Packaging:
.github/workflows/macos-zip.ymlrunning onmacos-15-intel(Intel x86-64 runner) to compile, test, package, and publish releases.packaging/macos/package.shto stage and packagedist/gow3-macos.zip.Launcher & Documentation:
launcher/gow3_launcher_win.pywith macOS system UI fonts, config paths in~/Library/Application Support/gow3-launcher, and folder/URL handling viaopen.run.pyandrun.shwith macOS environment paths.README.mdwith requirements and running instructions.