Index: ps/trunk/libraries/osx/build-osx-libs.sh =================================================================== --- ps/trunk/libraries/osx/build-osx-libs.sh +++ ps/trunk/libraries/osx/build-osx-libs.sh @@ -48,6 +48,7 @@ MINIUPNPC_VERSION="miniupnpc-2.2.2" SODIUM_VERSION="libsodium-1.0.18" FMT_VERSION="7.1.3" +MOLTENVK_VERSION="1.2.2" # -------------------------------------------------------------- # Bundled with the game: # * SpiderMonkey @@ -1039,6 +1040,33 @@ fi popd > /dev/null +# -------------------------------------------------------------- +echo -e "Building Molten VK..." +LIB_DIRECTORY="MoltenVK-$MOLTENVK_VERSION" +LIB_ARCHIVE="MoltenVK-$MOLTENVK_VERSION.tar.gz" +LIB_URL="https://releases.wildfiregames.com/libs/" + +mkdir -p "molten-vk" +pushd "molten-vk" > /dev/null +if [[ "$force_rebuild" = "true" ]] || [[ ! -e .already-built ]] || [[ "$(<.already-built)" != "$MOLTENVK_VERSION" ]] +then + INSTALL_DIR="../../../../binaries/system/" + rm -f .already-built + download_lib $LIB_URL $LIB_ARCHIVE + rm -rf "$LIB_DIRECTORY" + tar -xf $LIB_ARCHIVE + pushd $LIB_DIRECTORY + # The CI cannot build MoltenVK so we provide prebuild binaries instead. + # Use mv instead of copy to preserve binary signature integrity. See: + # https://developer.apple.com/forums/thread/130313?answerId=410541022#410541022 + mv dylib/libMoltenVK.dylib $INSTALL_DIR + popd > /dev/null + echo "$MOLTENVK_VERSION" > .already-built +else + already_built +fi +popd > /dev/null + # -------------------------------------------------------------------- # The following libraries are shared on different OSes and may # be customized, so we build and install them from bundled sources Index: ps/trunk/source/ps/DllLoader.h =================================================================== --- ps/trunk/source/ps/DllLoader.h +++ ps/trunk/source/ps/DllLoader.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2014 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -20,6 +20,7 @@ #include "ps/Errors.h" #include "ps/CLogger.h" +#include "ps/CStr.h" ERROR_GROUP(DllLoader); ERROR_TYPE(DllLoader, DllNotLoaded); @@ -76,6 +77,8 @@ */ static void OverrideLibdir(const char* libdir); + static CStr GenerateFilename(const CStr& name, const CStr& suffix, const CStr& extension); + private: // Typeless version - the public LoadSymbol hides the slightly ugly // casting from users. Index: ps/trunk/source/ps/DllLoader.cpp =================================================================== --- ps/trunk/source/ps/DllLoader.cpp +++ ps/trunk/source/ps/DllLoader.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -21,7 +21,6 @@ #include "lib/timer.h" #include "lib/posix/posix_dlfcn.h" -#include "ps/CStr.h" #if OS_MACOSX # include "lib/sysdep/os/osx/osx_bundle.h" @@ -69,7 +68,7 @@ // the naming/location convention above - it'll need to be changed if we want // to support other DLLs.) -static CStr GenerateFilename(const CStr& name, const CStr& suffix, const CStr& extension) +CStr DllLoader::GenerateFilename(const CStr& name, const CStr& suffix, const CStr& extension) { CStr n; @@ -114,7 +113,7 @@ { for (size_t idxExtension = 0; idxExtension < ARRAY_SIZE(extensions); idxExtension++) { - CStr filename = GenerateFilename(name, suffixes[idxSuffix], extensions[idxExtension]); + CStr filename = DllLoader::GenerateFilename(name, suffixes[idxSuffix], extensions[idxExtension]); // we don't really care when relocations take place, but one of // {RTLD_NOW, RTLD_LAZY} must be specified. go with the former because Index: ps/trunk/source/ps/VideoMode.cpp =================================================================== --- ps/trunk/source/ps/VideoMode.cpp +++ ps/trunk/source/ps/VideoMode.cpp @@ -29,6 +29,9 @@ #include "ps/CLogger.h" #include "ps/ConfigDB.h" #include "ps/CStr.h" +#if OS_MACOSX && SDL_VERSION_ATLEAST(2, 0, 6) +#include "ps/DllLoader.h" +#endif #include "ps/Filesystem.h" #include "ps/Game.h" #include "ps/GameSetup/Config.h" @@ -41,6 +44,11 @@ #include +#if OS_MACOSX && SDL_VERSION_ATLEAST(2, 0, 6) +#include +#include +#endif + namespace { @@ -391,6 +399,23 @@ flags |= SDL_WINDOW_VULKAN; m_WindowedX = m_WindowedY = SDL_WINDOWPOS_CENTERED_DISPLAY(m_ConfigDisplay); +#if OS_MACOSX && SDL_VERSION_ATLEAST(2, 0, 6) + if (m_Backend == Renderer::Backend::Backend::VULKAN) + { + // MoltenVK - enable full component swizzling support. + setenv("MVK_CONFIG_FULL_IMAGE_VIEW_SWIZZLE", "1", 1); + CStr fullPathToVulkanLibrary = DllLoader::GenerateFilename("MoltenVK", "", ".dylib"); + if (SDL_Vulkan_LoadLibrary(fullPathToVulkanLibrary.c_str()) != 0) + { + LOGWARNING("Failed to load %s.", fullPathToVulkanLibrary.c_str()); + DowngradeBackendSettingAfterCreationFailure(); + return SetVideoMode(w, h, bpp, fullscreen); + } + else + LOGMESSAGE("Loaded %s.", fullPathToVulkanLibrary.c_str()); + } +#endif + m_Window = SDL_CreateWindow(main_window_name, m_WindowedX, m_WindowedY, w, h, flags); if (!m_Window) { Index: ps/trunk/source/tools/dist/build-osx-bundle.py =================================================================== --- ps/trunk/source/tools/dist/build-osx-bundle.py +++ ps/trunk/source/tools/dist/build-osx-bundle.py @@ -60,6 +60,7 @@ print("Copying libs") shutil.copy("binaries/system/libAtlasUI.dylib", BUNDLE_FRAMEWORKS) shutil.copy("binaries/system/libCollada.dylib", BUNDLE_FRAMEWORKS) +shutil.copy("binaries/system/libMoltenVK.dylib", BUNDLE_FRAMEWORKS) if not args.dev: print("Copying archived game data from archives/")