From 5cbcadaa1e7ee3281cf066a1bee357ba91f730ca Mon Sep 17 00:00:00 2001 From: Brian Degenhardt Date: Sun, 12 Jul 2026 16:32:05 -0700 Subject: [PATCH] Fix desktop/Android build breaks from the ios/pr-ready merge The ios/pr-ready merge (04ea993e99) introduced two independent regressions in the shared core: 1. DEV9/AdapterUtils.cpp included Apple-only unconditionally under __POSIX__, so every non-Apple POSIX target (Linux, Android, FreeBSD) failed to compile. Guard the include with __APPLE__; TARGET_OS_IPHONE is only consulted to keep iOS out of the BSD-socket block, and on non-Apple it correctly evaluates to 0. 2. SPU2::RegisterNEONBackend() is called from spu2.cpp on every arm64 target (guarded by __aarch64__ / _M_ARM64), but spu2_neon.cpp was only added to the build for Android/iOS -- so desktop arm64 (macOS/Linux/Windows) failed to link with an undefined symbol. Compile spu2_neon.cpp on all ARCH_ARM64 targets. The NEON reverb backend stays opt-in (SPU2/NeonReverbSIMD, default off). While wiring it up for desktop: - Drop the unused spu2_neon_mixer/_reverb_ex/_dcfilter includes from spu2_neon.cpp. They hold helpers for a mixer.cpp/ReaVerb.cpp integration that hasn't happened, and use the MSVC-only __forceinline keyword unguarded (breaks clang). The TU only needs the reverb FIR plus the SVE2 hook. - Guard spu2_optimize.h's x86-only /_mm_prefetch off MSVC-on-ARM64 (falls back to the no-op prefetch). Verified locally: clean Release build + link on Linux arm64 (RegisterNEONBackend now defined in the binary). Co-Authored-By: Claude Opus 4.8 (1M context) --- pcsx2/CMakeLists.txt | 8 ++++++-- pcsx2/DEV9/AdapterUtils.cpp | 7 +++++++ pcsx2/SPU2/spu2_neon.cpp | 17 +++++++++++++---- pcsx2/SPU2/spu2_optimize.h | 5 ++++- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/pcsx2/CMakeLists.txt b/pcsx2/CMakeLists.txt index e82f82247f..5287fdf194 100644 --- a/pcsx2/CMakeLists.txt +++ b/pcsx2/CMakeLists.txt @@ -1115,8 +1115,12 @@ if(CMAKE_SYSTEM_NAME STREQUAL "iOS") set(ARMSX2_IOS TRUE) endif() -# NEON-optimised SPU2 mixer/reverb: shared by all arm64 mobile targets. -if(ANDROID OR ARMSX2_IOS) +# NEON-optimised SPU2 reverb FIR backend. Compiled on EVERY arm64 target +# (desktop macOS/Linux/Windows as well as Android/iOS): the call site in +# spu2.cpp is guarded only by __aarch64__ / _M_ARM64, so RegisterNEONBackend() +# must be defined on all arm64 builds or desktop arm64 fails to link. The +# feature itself stays opt-in via SPU2/NeonReverbSIMD (default off). +if(ANDROID OR ARMSX2_IOS OR ARCH_ARM64) list(APPEND pcsx2SPU2Sources SPU2/spu2_neon.cpp) list(APPEND pcsx2SPU2Headers diff --git a/pcsx2/DEV9/AdapterUtils.cpp b/pcsx2/DEV9/AdapterUtils.cpp index a65d1faad2..c0c0ead217 100644 --- a/pcsx2/DEV9/AdapterUtils.cpp +++ b/pcsx2/DEV9/AdapterUtils.cpp @@ -21,7 +21,14 @@ #include #include +// TargetConditionals.h (which defines TARGET_OS_IPHONE) is an Apple-only header. +// Guard the include so non-Apple POSIX targets (Linux, Android, FreeBSD) still +// build: on those, TARGET_OS_IPHONE is undefined and evaluates to 0 in the #if +// below, while the __FreeBSD__/__APPLE__ gate already keeps them out of the +// BSD-socket block. The net effect is that only iOS is excluded here. +#ifdef __APPLE__ #include +#endif #if (defined(__FreeBSD__) || (__APPLE__)) && !TARGET_OS_IPHONE #include #include diff --git a/pcsx2/SPU2/spu2_neon.cpp b/pcsx2/SPU2/spu2_neon.cpp index 0b7884e0d2..d89103173b 100644 --- a/pcsx2/SPU2/spu2_neon.cpp +++ b/pcsx2/SPU2/spu2_neon.cpp @@ -12,14 +12,23 @@ #if defined(__aarch64__) || defined(_M_ARM64) #include "SPU2/spu2_neon.h" -#include "SPU2/spu2_neon_mixer.h" -#include "SPU2/spu2_neon_reverb_ex.h" -#include "SPU2/spu2_neon_dcfilter.h" +// spu2_sve2_fir.h defines SPU2_HAS_SVE2_COMPILER and, when the compiler actually +// targets SVE2, TryRegisterSVE2FIR(); it also pulls in spu2_mt6899_tuning.h for +// runtime CPU feature detection. defs.h provides V_Core / StereoOut32 / +// clamp_mix and the ReverbDownsample/ReverbUpsample function pointers. #include "SPU2/spu2_sve2_fir.h" -#include "SPU2/spu2_mt6899_tuning.h" #include "SPU2/defs.h" +// NOTE: the spu2_neon_mixer / _reverb_ex / _dcfilter helper headers are +// intentionally NOT included. They hold drop-in SIMD helpers meant to be called +// from mixer.cpp / ReaVerb.cpp, but that integration hasn't been wired up — this +// TU only needs the reverb FIR below plus the SVE2 hook. Pulling them in would +// compile a pile of currently-unused (and not-yet-portable) code on every arm64 +// target (they use the MSVC-only __forceinline keyword unguarded). #include +#include +#include +#include #include // ============================================================================ diff --git a/pcsx2/SPU2/spu2_optimize.h b/pcsx2/SPU2/spu2_optimize.h index bb7e372e63..fd5e599fc1 100644 --- a/pcsx2/SPU2/spu2_optimize.h +++ b/pcsx2/SPU2/spu2_optimize.h @@ -22,13 +22,16 @@ #define SPU2_UNLIKELY(x) __builtin_expect(!!(x), 0) #define SPU2_PREFETCH_R(ptr) __builtin_prefetch((ptr), 0, 3) #define SPU2_PREFETCH_W(ptr) __builtin_prefetch((ptr), 1, 3) -#elif defined(_MSC_VER) +#elif defined(_MSC_VER) && !defined(_M_ARM64) && !defined(_M_ARM64EC) #include #define SPU2_LIKELY(x) (x) #define SPU2_UNLIKELY(x) (x) #define SPU2_PREFETCH_R(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T0) #define SPU2_PREFETCH_W(ptr) ((void)(ptr)) #else + // Fallback — includes MSVC on ARM64, which has no /_mm_prefetch + // (those are x86-only). Branch hints have no portable MSVC equivalent; the + // prefetch is a perf hint, so a no-op is functionally correct. #define SPU2_LIKELY(x) (x) #define SPU2_UNLIKELY(x) (x) #define SPU2_PREFETCH_R(ptr) ((void)(ptr))