Porting or building PCSX2 on Linux for aarch64 (ARM64) involves several considerations. Here’s a breakdown of what it would take, based on the provided repository context and PCSX2’s current capabilities:
1. Verify Existing ARM64 Support in PCSX2
PCSX2 already supports Apple Silicon (ARM64 macOS) to a limited extent, as mentioned in the ./repos/pcsx2/CMakeLists.txt file:
- Apple Silicon Support: The project has an incomplete implementation for ARM64. Specifically:
- It lacks EE/VU/IOP recompilers (dynarecs) for ARM64.
- Games run very slowly on ARM64 due to the absence of these recompilers, relying instead on interpreters.
On Linux aarch64, similar issues will arise. While the baseline code may compile, performance-critical components like the recompilers will need to be implemented and optimized for ARM64.
2. Dynarec Support for ARM64
- Current Status: PCSX2 has dynarecs (dynamic recompilers) for
x86 and x86_64. The ARM64 architecture will need its own dynarecs for the Emotion Engine (EE), Vector Units (VU), and Input/Output Processor (IOP) to achieve acceptable performance.
- Work Required:
- Port x86 Dynarecs to ARM64: Write ARM64-specific dynarecs for EE, VU, and IOP.
- Leverage Existing ARM64 Work: Study any ARM64-specific optimizations or code already implemented for Apple Silicon. This could help jumpstart the Linux ARM64 port.
- CPUINFO Library: The
cpuinfo library in the ./repos/pcsx2/3rdparty/cpuinfo directory already supports ARM64 and can help detect supported instruction sets (e.g., NEON, ARMv8.3 extensions) on Linux systems. Use this to tailor the dynarecs for ARM64.
3. Cross-Platform Build System
PCSX2 uses CMake as its build system, which supports cross-platform builds. The top-level CMakeLists.txt already includes OS and architecture detection logic:
- Current Logic:
- It checks for compilers (Clang/MSVC).
- It explicitly warns about unsupported configurations, including ARM64 for Apple Silicon.
- Work Required:
- Extend the CMake logic to recognize Linux
aarch64.
- Ensure proper handling of ARM64-specific flags and dependencies.
- Confirm that the build process integrates well with Linux system libraries such as OpenGL/Vulkan, SDL2, and audio backends.
4. Graphics Backends
PCSX2's graphics plugins include OpenGL and Vulkan backends, which are already cross-platform and compatible with ARM64 Linux systems:
- Vulkan: The Vulkan headers (
./repos/pcsx2/3rdparty/vulkan/README.md) and renderer code should work on ARM64 as long as the Vulkan driver is available on the target Linux system.
- OpenGL: Ensure the OpenGL renderer works with ARM64 Linux drivers (e.g., Mesa for Mali GPUs or proprietary drivers for other ARM GPUs).
No major changes should be required for graphics as long as the drivers are available.
5. Audio Backends
The cubeb audio library in ./repos/pcsx2/3rdparty/cubeb supports multiple platforms and backends, including ALSA and PulseAudio on Linux. Ensure that:
cubeb builds correctly for ARM64 Linux.
- The appropriate audio backend (e.g., ALSA) works without issues.
6. Dependencies and Third-Party Libraries
PCSX2 uses several third-party libraries. Most of these should already support ARM64 Linux:
- cpuinfo: Fully supports ARM64 Linux.
- cubeb: Supports Linux and ARM64.
- Vulkan-Headers: Cross-platform and ARM64-compatible.
- Other Libraries: Ensure all other dependencies (e.g., SDL2) are ARM64-compatible and available on the target Linux distribution.
7. Performance Optimizations
Once the ARM64 port is functional, performance optimizations will be critical. This includes:
- NEON Intrinsics: Use ARM NEON intrinsics for SIMD operations where available.
- Instruction Set Detection: Use
cpuinfo to detect ARM64-specific instruction sets and optimize accordingly.
- Testing Dynarecs: Benchmark and profile the new ARM64 dynarecs to identify bottlenecks.
8. Address Potential Issues
- Endianness: Ensure code assumes little-endian operation, as ARM64 is little-endian by default.
- Alignment: ARM64 has stricter alignment requirements than x86. Audit memory accesses in performance-critical code to ensure they are properly aligned.
9. Testing and Debugging
- Use an ARM64 Linux system (e.g., Raspberry Pi 4, Jetson Nano, or AWS Graviton instances) for testing.
- Debug and verify:
- Core emulator functionality.
- Graphics rendering (via OpenGL/Vulkan).
- Audio playback.
- Game compatibility.
Summary of Work Required
- ARM64 Dynarecs: Port or reimplement dynarecs for EE, VU, and IOP.
- CMake Build Integration: Extend the build system to handle Linux
aarch64.
- Dependency Compatibility: Ensure all third-party libraries build and work on ARM64 Linux.
- Graphics and Audio: Verify OpenGL/Vulkan and cubeb backends on ARM64.
- Performance Optimizations: Leverage NEON and ARM64-specific features.
- Thorough Testing: Test the port on real ARM64 hardware running Linux.
Conclusion
While PCSX2 already has some groundwork for ARM64 due to its Apple Silicon support, significant work is still needed to add proper recompilers (dynarecs) and fully optimize the emulator for Linux on ARM64. If you're interested in contributing, starting with the dynarecs would be the most impactful step.