diff --git a/.github/workflows/build-mvk.yml b/.github/workflows/build-mvk.yml new file mode 100644 index 0000000000..aa9c5901b5 --- /dev/null +++ b/.github/workflows/build-mvk.yml @@ -0,0 +1,43 @@ +name: Build MoltenVK +on: workflow_dispatch + +jobs: + build-macos: + name: Build macOS + runs-on: macos-13 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Build + run: osu.Framework.NativeLibs/scripts/moltenvk/build-macOS.sh + + - name: Upload + uses: actions/upload-artifact@v4 + with: + name: macOS-universal + path: macOS-universal + + make-pr: + name: Create pull request + runs-on: ubuntu-22.04 + needs: + - build-macos + steps: + - name: Checkout + uses: actions/checkout@v4 + + - uses: actions/download-artifact@v4 + with: + name: macOS-universal + path: osu.Framework.NativeLibs/runtimes/osx/native + + - uses: peter-evans/create-pull-request@v6 + with: + commit-message: Update MoltenVK binary + title: Update MoltenVK binary + body: This PR has been auto-generated to update the MoltenVK binary. + branch: update-mvk-binary + delete-branch: true + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true' diff --git a/.gitignore b/.gitignore index 841e492d7d..4dbec10ed5 100644 --- a/.gitignore +++ b/.gitignore @@ -346,4 +346,6 @@ inspectcode # NativeLibs build folders and tarballs osu.Framework.NativeLibs/scripts/ffmpeg/*/ osu.Framework.NativeLibs/scripts/ffmpeg/*.tar.gz +osu.Framework.NativeLibs/scripts/moltenvk/*/ +osu.Framework.NativeLibs/scripts/moltenvk/*.dylib diff --git a/osu.Framework.NativeLibs/runtimes/osx/native/libMoltenVK.dylib b/osu.Framework.NativeLibs/runtimes/osx/native/libMoltenVK.dylib new file mode 100755 index 0000000000..7fa64ecb7d Binary files /dev/null and b/osu.Framework.NativeLibs/runtimes/osx/native/libMoltenVK.dylib differ diff --git a/osu.Framework.NativeLibs/scripts/moltenvk/BUILDING.md b/osu.Framework.NativeLibs/scripts/moltenvk/BUILDING.md new file mode 100644 index 0000000000..f81b0d48d7 --- /dev/null +++ b/osu.Framework.NativeLibs/scripts/moltenvk/BUILDING.md @@ -0,0 +1,24 @@ +# Build Instructions + +NOTE: MoltenVK is supported only on Apple devices. + +1. Install the dependencies +2. Run the build script `build-macOS.sh` + +### Dependencies + +Check [this page](https://github.com/KhronosGroup/MoltenVK) for instructions on how to install dependencies. +It is enough to install these packages in addition to Xcode: + +```zsh +brew install git cmake python3 ninja make +``` + +## Output files + +The shared library will be located in the `macOS-universal` directory, +and the directory called `mvk-build` will contain the respective build files. + +## Cleanup + +Files are left around for debugging purposes, manually delete the directories to clean up. \ No newline at end of file diff --git a/osu.Framework.NativeLibs/scripts/moltenvk/build-macOS.sh b/osu.Framework.NativeLibs/scripts/moltenvk/build-macOS.sh new file mode 100755 index 0000000000..7535e5cf1e --- /dev/null +++ b/osu.Framework.NativeLibs/scripts/moltenvk/build-macOS.sh @@ -0,0 +1,21 @@ +#!/bin/zsh + +set -eu + +pushd . > /dev/null + +git clone "https://github.com/KhronosGroup/MoltenVK.git" "mvk-build" +cd "mvk-build" + +./fetchDependencies --macos -v + +make macos \ + MVK_CONFIG_LOG_LEVEL=1 \ + MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS=1 \ + MVK_CONFIG_SHOULD_MAXIMIZE_CONCURRENT_COMPILATION=1 \ + MVK_CONFIG_API_VERSION_TO_ADVERTISE=13 + +mkdir -p ../macOS-universal +cp "Package/Release/MoltenVK/dylib/macOS/libMoltenVK.dylib" "../macOS-universal/libMoltenVK.dylib" + +popd > /dev/null diff --git a/osu.Framework/Graphics/Veldrid/VeldridDevice.cs b/osu.Framework/Graphics/Veldrid/VeldridDevice.cs index aa0c31d479..9aa0498de3 100644 --- a/osu.Framework/Graphics/Veldrid/VeldridDevice.cs +++ b/osu.Framework/Graphics/Veldrid/VeldridDevice.cs @@ -134,9 +134,9 @@ public VeldridDevice(IGraphicsSurface graphicsSurface) case RuntimeInfo.Platform.macOS: { - // OpenGL doesn't use a swapchain, so it's only needed on Metal. + // OpenGL doesn't use a swapchain, so it's only needed on Metal/MoltenVK. // Creating a Metal surface in general would otherwise destroy the GL context. - if (this.graphicsSurface.Type == GraphicsSurfaceType.Metal) + if (this.graphicsSurface.Type != GraphicsSurfaceType.OpenGL) { var metalGraphics = (IMetalGraphicsSurface)this.graphicsSurface; swapchain.Source = SwapchainSource.CreateNSView(metalGraphics.CreateMetalView()); diff --git a/osu.Framework/Platform/GameHost.cs b/osu.Framework/Platform/GameHost.cs index a29c197f2d..289cf13e49 100644 --- a/osu.Framework/Platform/GameHost.cs +++ b/osu.Framework/Platform/GameHost.cs @@ -843,6 +843,17 @@ public IEnumerable GetPreferredRenderersForCurrentPlatform() { yield return RendererType.Automatic; + bool isVulkanSupported; + + try + { + isVulkanSupported = Veldrid.GraphicsDevice.IsBackendSupported(Veldrid.GraphicsBackend.Vulkan); + } + catch + { + isVulkanSupported = false; + } + // Preferred per-platform renderers switch (RuntimeInfo.OS) { @@ -850,14 +861,18 @@ public IEnumerable GetPreferredRenderersForCurrentPlatform() yield return RendererType.Direct3D11; yield return RendererType.Deferred_Direct3D11; yield return RendererType.OpenGL; - yield return RendererType.Deferred_Vulkan; + + if (isVulkanSupported) + yield return RendererType.Deferred_Vulkan; break; case RuntimeInfo.Platform.Linux: yield return RendererType.OpenGL; yield return RendererType.Deferred_OpenGL; - yield return RendererType.Deferred_Vulkan; + + if (isVulkanSupported) + yield return RendererType.Deferred_Vulkan; break; @@ -866,6 +881,9 @@ public IEnumerable GetPreferredRenderersForCurrentPlatform() yield return RendererType.Deferred_Metal; yield return RendererType.OpenGL; + if (isVulkanSupported) + yield return RendererType.Deferred_Vulkan; + break; case RuntimeInfo.Platform.iOS: