Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS: Apple Silicon support (interpreter only) #1255

Draft
wants to merge 30 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
08630f5
CI: Add macOS arm64 build
exverge-0 Jul 1, 2024
d2a9c31
ih264d: Modify to compile with AppleClang & for M1
exverge-0 Jul 1, 2024
5a3f864
When compiling for Apple Silicon, CMAKE_SYSTEM_PROCESSOR is set to ar…
exverge-0 Jul 6, 2024
dc1dc44
MMU: Align pre-core memory space for 16kib page size
exverge-0 Jul 3, 2024
6786bca
Implement _mm_mfence for aarch64
exverge-0 Jul 4, 2024
72af6e8
Hardcode frequency on Apple Silicon
exverge-0 Jul 6, 2024
011be25
coreinit: Split pointer before passing to FiberThreadEntry
exverge-0 Jul 10, 2024
e81a592
gui: Fix missing item on macOS
exverge-0 Jul 10, 2024
f4b59c9
Latte: Disable blending integer formats
exverge-0 Jul 11, 2024
b2330b3
Use interpreter on arm64 by default
exverge-0 Jul 11, 2024
f24fc3e
MMU: Make HIGHMEM address conditional
exverge-0 Jul 11, 2024
e6e65af
gx2: Use atomic pointers for GX2WriteGatherPipeState
exverge-0 Jul 12, 2024
10bed1a
Latte: decode indices with NEON on aarch64
exverge-0 Jul 17, 2024
804aa4f
ih264d: Process arguments correctly on Apple Silicon
exverge-0 Jul 19, 2024
005e78b
Set macOS frequency constant for Intel
exverge-0 Jul 20, 2024
4baad7c
CI: Use AppleClang for arm64
exverge-0 Jul 21, 2024
7037337
gui: don't use 1 as itemid
exverge-0 Jul 21, 2024
0760d3e
Update BUILD.md
exverge-0 Jul 23, 2024
b853614
Merge branch 'cemu-project:main' into macos-arm64
exverge-0 Jul 23, 2024
d25f8da
ih264: fix comment formatting
exverge-0 Jul 23, 2024
ca2a9ff
Merge remote-tracking branch 'base/main' into macos-arm64
exverge-0 Aug 7, 2024
a393ee8
Fix build errors
exverge-0 Aug 8, 2024
4700a19
Revert alignment of HIGHMEM
exverge-0 Aug 7, 2024
3795fc0
MemMapper: Support alternative pagesizes
exverge-0 Aug 7, 2024
118d1c6
Update BUILD.md
exverge-0 Aug 8, 2024
6b6a538
Update build.yml
exverge-0 Aug 8, 2024
d73c589
MemMapper: don't change address on non-reserved mappings
exverge-0 Aug 8, 2024
b30a6b0
Add suggested changes
exverge-0 Aug 8, 2024
86b477a
Revert "Update build.yml"
exverge-0 Aug 8, 2024
ee7c08e
Latte : Temporarily disable blending for integer format color attachm…
exverge-0 Aug 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 100 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ jobs:
name: cemu-bin-windows-x64
path: ./bin/Cemu.exe

build-macos:
build-macos-intel:
runs-on: macos-12
steps:
- name: "Checkout repo"
Expand Down Expand Up @@ -239,8 +239,7 @@ jobs:
- name: "Install system dependencies"
run: |
brew update
brew install llvm@15 ninja nasm automake libtool
brew install cmake python3 ninja
brew install llvm@15 ninja nasm automake libtool cmake python3 ninja

- name: "Build and install molten-vk"
run: |
Expand All @@ -251,11 +250,6 @@ jobs:
make macos
make install

- name: "Setup cmake"
uses: jwlawson/actions-setup-cmake@v2
with:
cmake-version: '3.29.0'

- name: "Bootstrap vcpkg"
run: |
bash ./dependencies/vcpkg/bootstrap-vcpkg.sh
Expand Down Expand Up @@ -308,3 +302,101 @@ jobs:
with:
name: cemu-bin-macos-x64
path: ./bin/Cemu.dmg

build-macos-arm64:
runs-on: macos-14
steps:
- name: "Checkout repo"
uses: actions/checkout@v4
with:
submodules: "recursive"

- name: "Fetch full history for vcpkg submodule"
run: |
cd dependencies/vcpkg
git fetch --unshallow

- name: Setup release mode parameters (for deploy)
if: ${{ inputs.deploymode == 'release' }}
run: |
echo "BUILD_MODE=release" >> $GITHUB_ENV
echo "BUILD_FLAGS=" >> $GITHUB_ENV
echo "Build mode is release"
- name: Setup debug mode parameters (for continous build)
if: ${{ inputs.deploymode != 'release' }}
run: |
echo "BUILD_MODE=debug" >> $GITHUB_ENV
echo "BUILD_FLAGS=" >> $GITHUB_ENV
echo "Build mode is debug"

- name: Setup version for experimental
if: ${{ inputs.experimentalversion != '' }}
run: |
echo "[INFO] Experimental version ${{ inputs.experimentalversion }}"
echo "BUILD_FLAGS=${{ env.BUILD_FLAGS }} -DEXPERIMENTAL_VERSION=${{ inputs.experimentalversion }}" >> $GITHUB_ENV

- name: "Install system dependencies"
run: |
brew update
brew install ninja automake libtool cmake ninja python3

- name: "Build and install molten-vk"
run: |
git clone https://github.com/KhronosGroup/MoltenVK.git
cd MoltenVK
git checkout bf097edc74ec3b6dfafdcd5a38d3ce14b11952d6
./fetchDependencies --macos
make macos
sudo make install
cp /usr/local/lib/libMoltenVK.dylib /opt/homebrew/lib

- name: "Bootstrap vcpkg"
run: |
bash ./dependencies/vcpkg/bootstrap-vcpkg.sh

- name: 'Setup NuGet Credentials for vcpkg'
shell: 'bash'
run: |
mono `./dependencies/vcpkg/vcpkg fetch nuget | tail -n 1` \
sources add \
-source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" \
-storepasswordincleartext \
-name "GitHub" \
-username "${{ github.repository_owner }}" \
-password "${{ secrets.GITHUB_TOKEN }}"
mono `./dependencies/vcpkg/vcpkg fetch nuget | tail -n 1` \
setapikey "${{ secrets.GITHUB_TOKEN }}" \
-source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"

- name: "cmake"
run: |
mkdir build
cd build
cmake .. ${{ env.BUILD_FLAGS }} \
-DCMAKE_BUILD_TYPE=${{ env.BUILD_MODE }} \
-DMACOS_BUNDLE=ON \
-G Ninja

- name: "Build Cemu"
run: |
cmake --build build

- name: Prepare artifact
if: ${{ inputs.deploymode == 'release' }}
run: |
mkdir bin/Cemu_app
mv bin/Cemu_release.app bin/Cemu_app/Cemu.app
mv bin/Cemu_app/Cemu.app/Contents/MacOS/Cemu_release bin/Cemu_app/Cemu.app/Contents/MacOS/Cemu
sed -i '' 's/Cemu_release/Cemu/g' bin/Cemu_app/Cemu.app/Contents/Info.plist
chmod a+x bin/Cemu_app/Cemu.app/Contents/MacOS/{Cemu,update.sh}
ln -s /Applications bin/Cemu_app/Applications
hdiutil create ./bin/tmp.dmg -ov -volname "Cemu" -fs HFS+ -srcfolder "./bin/Cemu_app"
hdiutil convert ./bin/tmp.dmg -format UDZO -o bin/Cemu.dmg
rm bin/tmp.dmg

- name: Upload artifact
uses: actions/upload-artifact@v4
if: ${{ inputs.deploymode == 'release' }}
with:
name: cemu-bin-macos-arm64
path: ./bin/Cemu.dmg
19 changes: 6 additions & 13 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
- [Compiling Errors](#compiling-errors)
- [Building Errors](#building-errors)
- [macOS](#macos)
- [On Apple Silicon Macs, Rosetta 2 and the x86_64 version of Homebrew must be used](#on-apple-silicon-macs-rosetta-2-and-the-x86_64-version-of-homebrew-must-be-used)
- [Installing brew](#installing-brew)
- [Installing Dependencies](#installing-dependencies)
- [Build Cemu using CMake and Clang](#build-cemu-using-cmake-and-clang)
Expand Down Expand Up @@ -142,21 +141,15 @@ If you are getting a different error than any of the errors listed above, you ma
## macOS

To compile Cemu, a recent enough compiler and STL with C++20 support is required! LLVM 13 and
below, built in LLVM, and Xcode LLVM don't support the C++20 feature set required. The OpenGL graphics
API isn't support on macOS, Vulkan must be used. Additionally Vulkan must be used through the
Molten-VK compatibility layer
lower don't support the C++20 feature set required. Cemu doesn't support using OpenGL
on macOS, Vulkan must be used via the Molten-Vk compatibility layer.

### On Apple Silicon Macs, Rosetta 2 and the x86_64 version of Homebrew must be used

You can skip this section if you have an Intel Mac. Every time you compile, you need to perform steps 2.

1. `softwareupdate --install-rosetta` # Install Rosetta 2 if you don't have it. This only has to be done once
2. `arch -x86_64 zsh` # run an x64 shell
Note that if you are compiling on/for Intel, you must replace all references of `/opt/homebrew` to `/usr/local`.

### Installing brew

1. `/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`
2. `eval "$(/usr/local/Homebrew/bin/brew shellenv)"` # set x86_64 brew env
2. `eval "$(/opt/homebrew/bin/brew shellenv)"` # set brew env

### Installing Dependencies

Expand All @@ -165,12 +158,12 @@ You can skip this section if you have an Intel Mac. Every time you compile, you
### Build Cemu using CMake and Clang
1. `git clone --recursive https://github.com/cemu-project/Cemu`
2. `cd Cemu`
3. `cmake -S . -B build -DCMAKE_BUILD_TYPE=release -DCMAKE_C_COMPILER=/usr/local/opt/llvm/bin/clang -DCMAKE_CXX_COMPILER=/usr/local/opt/llvm/bin/clang++ -G Ninja`
3. `cmake -S . -B build -DCMAKE_BUILD_TYPE=release -DCMAKE_C_COMPILER=/opt/homebrew/opt/llvm/bin/clang -DCMAKE_CXX_COMPILER=/opt/homebrew/opt/llvm/bin/clang++ -G Ninja`
4. `cmake --build build`
5. You should now have a Cemu executable file in the /bin folder, which you can run using `./bin/Cemu_release`.

#### Troubleshooting steps
- If step 3 gives you an error about not being able to find ninja, try appending `-DCMAKE_MAKE_PROGRAM=/usr/local/bin/ninja` to the command and running it again.
- If step 3 gives you an error about not being able to find ninja, try appending `-DCMAKE_MAKE_PROGRAM=/opt/homebrew/bin/ninja` to the command and running it again.

## Updating Cemu and source code
1. To update your Cemu local repository, use the command `git pull --recurse-submodules` (run this command on the Cemu root).
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
cmake_minimum_required(VERSION 3.21.1)

include(CMakeDependentOption)
option(ENABLE_VCPKG "Enable the vcpkg package manager" ON)
option(MACOS_BUNDLE "The executable when built on macOS will be created as an application bundle" OFF)
cmake_dependent_option(MACOS_BUNDLE "The executable when built on macOS will be created as an application bundle" ON "APPLE" OFF)
set(EXPERIMENTAL_VERSION "" CACHE STRING "") # used by CI script to set experimental version

if (EXPERIMENTAL_VERSION)
Expand Down
2 changes: 1 addition & 1 deletion dependencies/ih264d/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ target_sources(ih264d PRIVATE
"decoder/x86/ih264d_function_selector_sse42.c"
"decoder/x86/ih264d_function_selector_ssse3.c"
)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
enable_language( C CXX ASM )
set(LIBAVCDEC_ARM_INCLUDES "common/armv8" "decoder/arm")
include_directories("common/" "decoder/" ${LIBAVCDEC_ARM_INCLUDES})
Expand Down
19 changes: 15 additions & 4 deletions dependencies/ih264d/common/armv8/ih264_intra_pred_chroma_av8.s
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@
.text
.p2align 2
.include "ih264_neon_macros.s"

#ifdef __APPLE__
.extern _ih264_gai1_intrapred_chroma_plane_coeffs1
.extern _ih264_gai1_intrapred_chroma_plane_coeffs2
#else
.extern ih264_gai1_intrapred_chroma_plane_coeffs1
.extern ih264_gai1_intrapred_chroma_plane_coeffs2

#endif


///**
Expand Down Expand Up @@ -429,8 +432,13 @@ ih264_intra_pred_chroma_8x8_mode_plane_av8:
rev64 v7.4h, v2.4h
ld1 {v3.2s}, [x10]
sub x5, x3, #8
#ifdef __APPLE__
adrp x12, _ih264_gai1_intrapred_chroma_plane_coeffs1@GOTPAGE
ldr x12, [x12, _ih264_gai1_intrapred_chroma_plane_coeffs1@GOTPAGEOFF]
#else
adrp x12, :got:ih264_gai1_intrapred_chroma_plane_coeffs1
ldr x12, [x12, #:got_lo12:ih264_gai1_intrapred_chroma_plane_coeffs1]
#endif
usubl v10.8h, v5.8b, v1.8b
ld1 {v8.8b, v9.8b}, [x12] // Load multiplication factors 1 to 8 into D3
mov v8.d[1], v9.d[0]
Expand Down Expand Up @@ -484,10 +492,13 @@ ih264_intra_pred_chroma_8x8_mode_plane_av8:
zip1 v1.8h, v0.8h, v2.8h
zip2 v2.8h, v0.8h, v2.8h
mov v0.16b, v1.16b

#ifdef __APPLE__
adrp x12, _ih264_gai1_intrapred_chroma_plane_coeffs2@GOTPAGE
ldr x12, [x12, _ih264_gai1_intrapred_chroma_plane_coeffs2@GOTPAGEOFF]
#else
adrp x12, :got:ih264_gai1_intrapred_chroma_plane_coeffs2
ldr x12, [x12, #:got_lo12:ih264_gai1_intrapred_chroma_plane_coeffs2]

#endif
ld1 {v8.2s, v9.2s}, [x12]
mov v8.d[1], v9.d[0]
mov v10.16b, v8.16b
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@
.text
.p2align 2
.include "ih264_neon_macros.s"
#ifdef __APPLE__
.extern _ih264_gai1_intrapred_luma_plane_coeffs
#else
.extern ih264_gai1_intrapred_luma_plane_coeffs
#endif



Expand Down Expand Up @@ -431,10 +435,13 @@ ih264_intra_pred_luma_16x16_mode_plane_av8:
mov x10, x1 //top_left
mov x4, #-1
ld1 {v2.2s}, [x1], x8

#ifdef __APPLE__
adrp x7, _ih264_gai1_intrapred_luma_plane_coeffs@GOTPAGE
ldr x7, [x7, _ih264_gai1_intrapred_luma_plane_coeffs@GOTPAGEOFF]
#else
adrp x7, :got:ih264_gai1_intrapred_luma_plane_coeffs
ldr x7, [x7, #:got_lo12:ih264_gai1_intrapred_luma_plane_coeffs]

#endif
ld1 {v0.2s}, [x1]
rev64 v2.8b, v2.8b
ld1 {v6.2s, v7.2s}, [x7]
Expand Down
11 changes: 9 additions & 2 deletions dependencies/ih264d/common/armv8/ih264_intra_pred_luma_8x8_av8.s
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@
.text
.p2align 2
.include "ih264_neon_macros.s"

#ifdef __APPLE__
.extern _ih264_gai1_intrapred_luma_8x8_horz_u
#else
.extern ih264_gai1_intrapred_luma_8x8_horz_u
#endif



Expand Down Expand Up @@ -1029,9 +1032,13 @@ ih264_intra_pred_luma_8x8_mode_horz_u_av8:
mov v3.d[0], v2.d[1]
ext v4.16b, v2.16b , v2.16b , #1
mov v5.d[0], v4.d[1]

#ifdef __APPLE__
adrp x12, _ih264_gai1_intrapred_luma_8x8_horz_u@GOTPAGE
ldr x12, [x12, _ih264_gai1_intrapred_luma_8x8_horz_u@GOTPAGEOFF]
#else
adrp x12, :got:ih264_gai1_intrapred_luma_8x8_horz_u
ldr x12, [x12, #:got_lo12:ih264_gai1_intrapred_luma_8x8_horz_u]
#endif
uaddl v20.8h, v0.8b, v2.8b
uaddl v22.8h, v1.8b, v3.8b
uaddl v24.8h, v2.8b, v4.8b
Expand Down
31 changes: 23 additions & 8 deletions dependencies/ih264d/common/armv8/ih264_weighted_bi_pred_av8.s
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,22 @@ ih264_weighted_bi_pred_luma_av8:
sxtw x4, w4
sxtw x5, w5
stp x19, x20, [sp, #-16]!
#ifndef __APPLE__
ldr w8, [sp, #80] //Load wt2 in w8
ldr w9, [sp, #88] //Load ofst1 in w9
add w6, w6, #1 //w6 = log_WD + 1
neg w10, w6 //w10 = -(log_WD + 1)
dup v0.8h, w10 //Q0 = -(log_WD + 1) (32-bit)
ldr w10, [sp, #96] //Load ofst2 in w10
ldr w11, [sp, #104] //Load ht in w11
ldr w12, [sp, #112] //Load wd in w12
#else
ldr w8, [sp, #80] //Load wd in w8
ldr w9, [sp, #84] //Load ht in w9
ldr w10, [sp, #88] //Load offst2 in w10
ldr w11, [sp, #92] //Load offst1 in w11
ldr w12, [sp, #96] //Load offst1 in w12
#endif
add w6, w6, #1 //w6 = log_WD + 1
neg w10, w6 //w10 = -(log_WD + 1)
dup v0.8h, w10 //Q0 = -(log_WD + 1) (32-bit)
add w9, w9, #1 //w9 = ofst1 + 1
add w9, w9, w10 //w9 = ofst1 + ofst2 + 1
mov v2.s[0], w7
Expand Down Expand Up @@ -424,17 +432,24 @@ ih264_weighted_bi_pred_chroma_av8:
sxtw x5, w5
stp x19, x20, [sp, #-16]!


#ifndef __APPLE__
ldr w8, [sp, #80] //Load wt2 in w8
ldr w9, [sp, #88] //Load ofst1 in w9
ldr w10, [sp, #96] //Load ofst2 in w10
ldr w11, [sp, #104] //Load ht in w11
ldr w12, [sp, #112] //Load wd in w12
#else
ldr w8, [sp, #80] //Load wd in w8
ldr w9, [sp, #84] //Load ht in w9
ldr w10, [sp, #88] //Load offst2 in w10
ldr w11, [sp, #92] //Load offst1 in w11
ldr w12, [sp, #96] //Load offst1 in w12
#endif
dup v4.4s, w8 //Q2 = (wt2_u, wt2_v) (32-bit)
dup v2.4s, w7 //Q1 = (wt1_u, wt1_v) (32-bit)
add w6, w6, #1 //w6 = log_WD + 1
ldr w9, [sp, #88] //Load ofst1 in w9
ldr w10, [sp, #96] //Load ofst2 in w10
neg w20, w6 //w20 = -(log_WD + 1)
dup v0.8h, w20 //Q0 = -(log_WD + 1) (16-bit)
ldr w11, [sp, #104] //Load ht in x11
ldr w12, [sp, #112] //Load wd in x12
dup v20.8h, w9 //0ffset1
dup v21.8h, w10 //0ffset2
srhadd v6.8b, v20.8b, v21.8b
Expand Down
Loading
Loading