Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
43 changes: 43 additions & 0 deletions .github/workflows/build-mvk.yml
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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

Binary file not shown.
24 changes: 24 additions & 0 deletions osu.Framework.NativeLibs/scripts/moltenvk/BUILDING.md
Original file line number Diff line number Diff line change
@@ -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.
21 changes: 21 additions & 0 deletions osu.Framework.NativeLibs/scripts/moltenvk/build-macOS.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions osu.Framework/Graphics/Veldrid/VeldridDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
22 changes: 20 additions & 2 deletions osu.Framework/Platform/GameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -843,21 +843,36 @@ public IEnumerable<RendererType> 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)
{
case RuntimeInfo.Platform.Windows:
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;

Expand All @@ -866,6 +881,9 @@ public IEnumerable<RendererType> GetPreferredRenderersForCurrentPlatform()
yield return RendererType.Deferred_Metal;
yield return RendererType.OpenGL;

if (isVulkanSupported)
yield return RendererType.Deferred_Vulkan;

break;

case RuntimeInfo.Platform.iOS:
Expand Down
Loading