From 40e8a40ada9a707b7cf3001ed1d8f835d0c7d2ad Mon Sep 17 00:00:00 2001 From: squidbus <175574877+squidbus@users.noreply.github.com> Date: Sat, 14 Dec 2024 00:20:04 -0800 Subject: [PATCH] externals: Add MoltenVK as an external. (#1767) --- .github/workflows/build.yml | 14 ++---- .gitmodules | 14 +++++- CMakeLists.txt | 3 +- documents/building-macos.md | 8 ++- externals/CMakeLists.txt | 24 +++++---- externals/MoltenVK/CMakeLists.txt | 81 +++++++++++++++++++++++++++++++ externals/MoltenVK/MoltenVK | 1 + externals/MoltenVK/SPIRV-Cross | 1 + externals/MoltenVK/cereal | 1 + 9 files changed, 119 insertions(+), 28 deletions(-) create mode 100644 externals/MoltenVK/CMakeLists.txt create mode 160000 externals/MoltenVK/MoltenVK create mode 160000 externals/MoltenVK/SPIRV-Cross create mode 160000 externals/MoltenVK/cereal diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bacfbea0..3b569043 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -174,11 +174,6 @@ jobs: with: xcode-version: latest - - name: Install MoltenVK - run: | - arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - arch -x86_64 /usr/local/bin/brew install molten-vk - - name: Cache CMake Configuration uses: actions/cache@v4 env: @@ -210,7 +205,7 @@ jobs: run: | mkdir upload mv ${{github.workspace}}/build/shadps4 upload - cp $(arch -x86_64 /usr/local/bin/brew --prefix)/opt/molten-vk/lib/libMoltenVK.dylib upload + cp ${{github.workspace}}/build/externals/MoltenVK/libMoltenVK.dylib upload tar cf shadps4-macos-sdl.tar.gz -C upload . - uses: actions/upload-artifact@v4 with: @@ -230,11 +225,8 @@ jobs: with: xcode-version: latest - - name: Install MoltenVK and Setup Qt - run: | - arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - arch -x86_64 /usr/local/bin/brew install molten-vk - - uses: jurplel/install-qt-action@v4 + - name: Setup Qt + uses: jurplel/install-qt-action@v4 with: version: 6.7.3 host: mac diff --git a/.gitmodules b/.gitmodules index 8010250a..3d0d21c5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -106,4 +106,16 @@ [submodule "externals/libpng"] path = externals/libpng url = https://github.com/pnggroup/libpng - shallow = true \ No newline at end of file + shallow = true +[submodule "externals/MoltenVK/SPIRV-Cross"] + path = externals/MoltenVK/SPIRV-Cross + url = https://github.com/KhronosGroup/SPIRV-Cross + shallow = true +[submodule "externals/MoltenVK/MoltenVK"] + path = externals/MoltenVK/MoltenVK + url = https://github.com/KhronosGroup/MoltenVK + shallow = true +[submodule "externals/MoltenVK/cereal"] + path = externals/MoltenVK/cereal + url = https://github.com/USCiLab/cereal + shallow = true diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e21a33c..1e54f7a0 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -894,8 +894,7 @@ if (APPLE) target_compile_definitions(shadps4 PRIVATE USE_SYSTEM_VULKAN_LOADER=1) else() # Link MoltenVK for Vulkan support - find_library(MOLTENVK MoltenVK REQUIRED) - target_link_libraries(shadps4 PRIVATE ${MOLTENVK}) + target_link_libraries(shadps4 PRIVATE MoltenVK) endif() if (ARCHITECTURE STREQUAL "x86_64") diff --git a/documents/building-macos.md b/documents/building-macos.md index d8cc414e..9a1a021e 100644 --- a/documents/building-macos.md +++ b/documents/building-macos.md @@ -24,23 +24,21 @@ eval $(/opt/homebrew/bin/brew shellenv) brew install clang-format cmake ``` -Next, install x86_64 Homebrew and libraries. +Next, install x86_64 Qt. You can skip these steps and move on to **Cloning and compiling** if you do not intend to build the Qt GUI. **If you are on an ARM Mac:** ``` # Installs x86_64 Homebrew to /usr/local arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" # Installs libraries. -arch -x86_64 /usr/local/bin/brew install molten-vk qt@6 +arch -x86_64 /usr/local/bin/brew install qt@6 ``` **If you are on an x86_64 Mac:** ``` -brew install molten-vk qt@6 +brew install qt@6 ``` -If you don't need the Qt GUI you can remove `qt@6` from the last command. - ### Cloning and compiling: Clone the repository recursively: diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index dcc9d2bc..1ab23a40 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt @@ -177,15 +177,6 @@ if (NOT TARGET PNG::PNG) add_library(PNG::PNG ALIAS png_static) endif() -if (APPLE) - # date - if (NOT TARGET date::date-tz) - option(BUILD_TZ_LIB "" ON) - option(USE_SYSTEM_TZ_DB "" ON) - add_subdirectory(date) - endif() -endif() - # Dear ImGui add_library(Dear_ImGui dear_imgui/imgui.cpp @@ -232,3 +223,18 @@ if (NOT TARGET stb::headers) target_include_directories(stb INTERFACE stb) add_library(stb::headers ALIAS stb) endif() + +# Apple-only dependencies +if (APPLE) + # date + if (NOT TARGET date::date-tz) + option(BUILD_TZ_LIB "" ON) + option(USE_SYSTEM_TZ_DB "" ON) + add_subdirectory(date) + endif() + + # MoltenVK + if (NOT TARGET MoltenVK) + add_subdirectory(MoltenVK) + endif() +endif() diff --git a/externals/MoltenVK/CMakeLists.txt b/externals/MoltenVK/CMakeLists.txt new file mode 100644 index 00000000..00e3231e --- /dev/null +++ b/externals/MoltenVK/CMakeLists.txt @@ -0,0 +1,81 @@ +# SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +# SPDX-License-Identifier: GPL-2.0-or-later + +# Prepare version information +find_package(Git) +if(GIT_FOUND) + execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD + OUTPUT_VARIABLE MVK_GIT_REV + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) +endif() +set(MVK_VERSION "1.2.12") +set(MVK_GENERATED_INCLUDES ${CMAKE_CURRENT_BINARY_DIR}/Generated) +file(WRITE ${MVK_GENERATED_INCLUDES}/mvkGitRevDerived.h "static const char* mvkRevString = \"${MVK_GIT_REV}\";") + +# Find required system libraries +find_library(APPKIT_LIBRARY AppKit REQUIRED) +find_library(FOUNDATION_LIBRARY Foundation REQUIRED) +find_library(IOKIT_LIBRARY IOKit REQUIRED) +find_library(IOSURFACE_LIBRARY IOSurface REQUIRED) +find_library(METAL_LIBRARY Metal REQUIRED) +find_library(QUARTZCORE_LIBRARY QuartzCore REQUIRED) + +# cereal +option(SKIP_PORTABILITY_TEST "" ON) +option(BUILD_DOC "" OFF) +option(BUILD_SANDBOX "" OFF) +option(SKIP_PERFORMANCE_COMPARISON "" ON) +option(SPIRV_CROSS_SKIP_INSTALL "" ON) +add_subdirectory(cereal) + +# SPIRV-Cross +option(SPIRV_CROSS_CLI "" OFF) +option(SPIRV_CROSS_ENABLE_TESTS "" OFF) +option(SPIRV_CROSS_ENABLE_HLSL "" OFF) +option(SPIRV_CROSS_ENABLE_CPP "" OFF) +option(SPIRV_CROSS_SKIP_INSTALL "" ON) +add_subdirectory(SPIRV-Cross) + +# Common +set(MVK_COMMON_DIR ${CMAKE_CURRENT_SOURCE_DIR}/MoltenVK/Common) +file(GLOB_RECURSE MVK_COMMON_SOURCES CONFIGURE_DEPENDS + ${MVK_COMMON_DIR}/*.cpp + ${MVK_COMMON_DIR}/*.m + ${MVK_COMMON_DIR}/*.mm) +set(MVK_COMMON_INCLUDES ${MVK_COMMON_DIR}) + +add_library(MoltenVKCommon STATIC ${MVK_COMMON_SOURCES}) +target_include_directories(MoltenVKCommon PUBLIC ${MVK_COMMON_INCLUDES}) +target_compile_options(MoltenVKCommon PRIVATE -w) + +# MoltenVKShaderConverter +set(MVK_SHADER_CONVERTER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/MoltenVK/MoltenVKShaderConverter) +file(GLOB_RECURSE MVK_SHADER_CONVERTER_SOURCES CONFIGURE_DEPENDS + ${MVK_SHADER_CONVERTER_DIR}/MoltenVKShaderConverter/*.cpp + ${MVK_SHADER_CONVERTER_DIR}/MoltenVKShaderConverter/*.m + ${MVK_SHADER_CONVERTER_DIR}/MoltenVKShaderConverter/*.mm) +set(MVK_SHADER_CONVERTER_INCLUDES ${MVK_SHADER_CONVERTER_DIR} ${MVK_SHADER_CONVERTER_DIR}/include) + +add_library(MoltenVKShaderConverter STATIC ${MVK_SHADER_CONVERTER_SOURCES}) +target_include_directories(MoltenVKShaderConverter PUBLIC ${MVK_SHADER_CONVERTER_INCLUDES}) +target_compile_options(MoltenVKShaderConverter PRIVATE -w) +target_link_libraries(MoltenVKShaderConverter PRIVATE spirv-cross-msl spirv-cross-reflect MoltenVKCommon) +target_compile_definitions(MoltenVKShaderConverter PRIVATE MVK_EXCLUDE_SPIRV_TOOLS=1) + +# MoltenVK +set(MVK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/MoltenVK/MoltenVK) +file(GLOB_RECURSE MVK_SOURCES CONFIGURE_DEPENDS + ${MVK_DIR}/MoltenVK/*.cpp + ${MVK_DIR}/MoltenVK/*.m + ${MVK_DIR}/MoltenVK/*.mm) +file(GLOB MVK_SRC_INCLUDES LIST_DIRECTORIES ON ${MVK_DIR}/MoltenVK/*) +set(MVK_INCLUDES ${MVK_SRC_INCLUDES} ${MVK_GENERATED_INCLUDES} ${MVK_DIR}/include) + +add_library(MoltenVK SHARED ${MVK_SOURCES}) +target_include_directories(MoltenVK PRIVATE ${MVK_INCLUDES}) +target_compile_options(MoltenVK PRIVATE -w) +target_link_libraries(MoltenVK PRIVATE + ${APPKIT_LIBRARY} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY} ${IOSURFACE_LIBRARY} ${METAL_LIBRARY} ${QUARTZCORE_LIBRARY} + Vulkan::Headers cereal::cereal spirv-cross-msl MoltenVKCommon MoltenVKShaderConverter) +target_compile_definitions(MoltenVK PRIVATE MVK_FRAMEWORK_VERSION=${MVK_VERSION} MVK_USE_METAL_PRIVATE_API=1) diff --git a/externals/MoltenVK/MoltenVK b/externals/MoltenVK/MoltenVK new file mode 160000 index 00000000..5ad3ee5d --- /dev/null +++ b/externals/MoltenVK/MoltenVK @@ -0,0 +1 @@ +Subproject commit 5ad3ee5d2f84342950c3fe93dec97719574d1932 diff --git a/externals/MoltenVK/SPIRV-Cross b/externals/MoltenVK/SPIRV-Cross new file mode 160000 index 00000000..6173e24b --- /dev/null +++ b/externals/MoltenVK/SPIRV-Cross @@ -0,0 +1 @@ +Subproject commit 6173e24b31f09a0c3217103a130e74c4ddec14a6 diff --git a/externals/MoltenVK/cereal b/externals/MoltenVK/cereal new file mode 160000 index 00000000..d1fcec80 --- /dev/null +++ b/externals/MoltenVK/cereal @@ -0,0 +1 @@ +Subproject commit d1fcec807b372f04e4c1041b3058e11c12853e6e