Skip to content

Commit

Permalink
Support MoltenVK (#1623)
Browse files Browse the repository at this point in the history
* start of Support MoltenVK

* Load static library

* Add MoltenVk native project

* rework checking library name

* add MoltenVk as submodule
Compile MoltenVK with Nuke
take only necessary libraries into MoltenVK package instead of the full xcframework

* change path to libraries in package
add installing of ninja build system for compiling MoltenVK

* add MoltenVK workflows

* Use PInvokeOverride for loading libraries on iOS and MacCatalyst

* Update src/Vulkan/Silk.NET.Vulkan/PreventSilkTouchBugAttribute.cs

Co-authored-by: Dylan Perks <11160611+Perksey@users.noreply.github.com>

---------

Co-authored-by: Valentin <valentin.zy@yandex.ru>
Co-authored-by: Dylan Perks <11160611+Perksey@users.noreply.github.com>
  • Loading branch information
3 people committed Sep 9, 2023
1 parent 59f25bb commit fdd0f40
Show file tree
Hide file tree
Showing 14 changed files with 168 additions and 1 deletion.
52 changes: 52 additions & 0 deletions .github/workflows/moltenvk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: MoltenVK
on:
push:
branches-ignore:
- "ci/*"
- "develop/*"
- "main"
paths:
- build/submodules/MoltenVK
- build/nuke/Native/Core.cs
- build/nuke/Native/MoltenVK.cs
- .github/workflows/moltenvk.yml
jobs:
Build:
strategy:
fail-fast: false
matrix:
env:
- os: macos-latest
name: Darwin
nuke_invoke: ./build.sh
extras: ""
name: ${{ matrix.env.name }} Build
runs-on: ${{ matrix.env.os }}
steps:
- uses: actions/checkout@v2
with:
token: ${{ secrets.PUSHABLE_GITHUB_TOKEN }}

- name: Checkout submodules, configure git
run: |
git -c submodule.third_party/git-hooks.update=none submodule update --init --recursive build/submodules/MoltenVK
git config --local user.email "9011267+dotnet-bot@users.noreply.github.com"
git config --local user.name "The Silk.NET Automaton"
- name: Extra prerequisites
run: |
echo running extras
${{ matrix.env.extras }}
# Install python
- uses: actions/setup-python@v4
with:
python-version: '3.10'

# Install CMake and Ninja
- uses: lukka/get-cmake@latest

- name: Build MoltenVK
run: ${{ matrix.env.nuke_invoke }} MoltenVK
env:
PUSHABLE_GITHUB_TOKEN: ${{ secrets.PUSHABLE_GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@
[submodule "build/submodules/shaderc"]
path = build/submodules/shaderc
url = https://github.com/google/shaderc
[submodule "build/submodules/MoltenVK"]
path = build/submodules/MoltenVK
url = https://github.com/KhronosGroup/MoltenVK
2 changes: 2 additions & 0 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
"FullPack",
"FullPushToNuGet",
"GLFW",
"MoltenVK",
"Pack",
"Prerequisites",
"PushToNuGet",
Expand Down Expand Up @@ -195,6 +196,7 @@
"FullPack",
"FullPushToNuGet",
"GLFW",
"MoltenVK",
"Pack",
"Prerequisites",
"PushToNuGet",
Expand Down
15 changes: 15 additions & 0 deletions Silk.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.Shaderc", "src\SPI
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.Shaderc.Native", "src\Native\Silk.NET.Shaderc.Native\Silk.NET.Shaderc.Native.csproj", "{D1E4EDC7-0A06-498A-B0F9-275B7D508A0E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.MoltenVK.Native", "src\Native\Silk.NET.MoltenVK.Native\Silk.NET.MoltenVK.Native.csproj", "{32BE0963-C372-4BCA-A7C2-3CA844FDBB78}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -3615,6 +3617,18 @@ Global
{D1E4EDC7-0A06-498A-B0F9-275B7D508A0E}.Release|x64.Build.0 = Release|Any CPU
{D1E4EDC7-0A06-498A-B0F9-275B7D508A0E}.Release|x86.ActiveCfg = Release|Any CPU
{D1E4EDC7-0A06-498A-B0F9-275B7D508A0E}.Release|x86.Build.0 = Release|Any CPU
{32BE0963-C372-4BCA-A7C2-3CA844FDBB78}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{32BE0963-C372-4BCA-A7C2-3CA844FDBB78}.Debug|Any CPU.Build.0 = Debug|Any CPU
{32BE0963-C372-4BCA-A7C2-3CA844FDBB78}.Debug|x64.ActiveCfg = Debug|Any CPU
{32BE0963-C372-4BCA-A7C2-3CA844FDBB78}.Debug|x64.Build.0 = Debug|Any CPU
{32BE0963-C372-4BCA-A7C2-3CA844FDBB78}.Debug|x86.ActiveCfg = Debug|Any CPU
{32BE0963-C372-4BCA-A7C2-3CA844FDBB78}.Debug|x86.Build.0 = Debug|Any CPU
{32BE0963-C372-4BCA-A7C2-3CA844FDBB78}.Release|Any CPU.ActiveCfg = Release|Any CPU
{32BE0963-C372-4BCA-A7C2-3CA844FDBB78}.Release|Any CPU.Build.0 = Release|Any CPU
{32BE0963-C372-4BCA-A7C2-3CA844FDBB78}.Release|x64.ActiveCfg = Release|Any CPU
{32BE0963-C372-4BCA-A7C2-3CA844FDBB78}.Release|x64.Build.0 = Release|Any CPU
{32BE0963-C372-4BCA-A7C2-3CA844FDBB78}.Release|x86.ActiveCfg = Release|Any CPU
{32BE0963-C372-4BCA-A7C2-3CA844FDBB78}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -3904,6 +3918,7 @@ Global
{1E7C6166-58B2-46B3-A9BA-18099BD83AF0} = {20A4A2D1-D699-4D71-AA97-950154638576}
{E77BE8DB-3C74-42EB-9B65-67EAAA9AD7DB} = {15FC3D1A-25D7-446B-87A7-B45BA3C2225F}
{D1E4EDC7-0A06-498A-B0F9-275B7D508A0E} = {72E7FA64-5B1E-477D-BD30-63B7F206B3C4}
{32BE0963-C372-4BCA-A7C2-3CA844FDBB78} = {72E7FA64-5B1E-477D-BD30-63B7F206B3C4}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F5273D7F-3334-48DF-94E3-41AE6816CD4D}
Expand Down
39 changes: 39 additions & 0 deletions build/nuke/Native/MoltenVK.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.Tooling;
using static Nuke.Common.IO.FileSystemTasks;

partial class Build {
AbsolutePath MoltenVKPath => RootDirectory / "build" / "submodules" / "MoltenVK";

Target MoltenVK => CommonTarget
(
x => x.Before(Compile)
.After(Clean)
.Executes
(
() =>
{
if (OperatingSystem.IsMacOS())
{
var runtimes = RootDirectory / "src" / "Native" / "Silk.NET.MoltenVK.Native" / "runtimes";
InheritedShell($"./fetchDependencies --ios --iossim --maccat", MoltenVKPath).AssertZeroExitCode();
InheritedShell($"make ios iossim maccat", MoltenVKPath).AssertZeroExitCode();
var xcFrameworkDir = MoltenVKPath / "Package" / "Release" / "MoltenVK" / "MoltenVK.xcframework";
CopyFile(xcFrameworkDir / "ios-arm64" / "libMoltenVK.a", runtimes / "ios" / "native" / "libMoltenVK.a", FileExistsPolicy.Overwrite);
CopyFile(xcFrameworkDir / "ios-arm64_x86_64-simulator" / "libMoltenVK.a", runtimes / "iossimulator" / "native" / "libMoltenVK.a", FileExistsPolicy.Overwrite);
CopyFile(xcFrameworkDir / "ios-arm64_x86_64-maccatalyst" / "libMoltenVK.a", runtimes / "maccatalyst" / "native" / "libMoltenVK.a", FileExistsPolicy.Overwrite);
}
PrUpdatedNativeBinary("MoltenVK");
}
)
);
}
1 change: 1 addition & 0 deletions build/submodules/MoltenVK
Submodule MoltenVK added at 02a8c0
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\build\props\common.props" />
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Authors>.NET Foundation and Contributors</Authors>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/dotnet/Silk.NET</PackageProjectUrl>
<Description>MoltenVK static library.</Description>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/KhronosGroup/MoltenVK</RepositoryUrl>
<IncludeBuildOutput>false</IncludeBuildOutput>
<IncludeContentInPack>true</IncludeContentInPack>
</PropertyGroup>
<ItemGroup>
<Content Include="runtimes\iossimulator\native\libMoltenVK.a" PackagePath="runtimes\iossimulator\native\libMoltenVK.a" />
<Content Include="runtimes\maccatalyst\native\libMoltenVK.a" PackagePath="runtimes\maccatalyst\native\libMoltenVK.a" />
<Content Include="runtimes\ios\native\libMoltenVK.a" PackagePath="runtimes\ios\native\libMoltenVK.a" />
<Content Include="build\netstandard2.0\Silk.NET.MoltenVK.Native.targets" PackagePath="build\netstandard2.0\Silk.NET.MoltenVK.Native.targets" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project ToolsVersion="15.0">
<PropertyGroup>
<_LibMoltenVKPath Condition="'$(RuntimeIdentifier)' == 'maccatalyst-x64' OR '$(RuntimeIdentifier)' == 'maccatalyst-arm64'">$(MSBuildThisFileDirectory)..\..\runtimes\maccatalyst\native\libMoltenVK.a</_LibMoltenVKPath>
<_LibMoltenVKPath Condition="$(RuntimeIdentifier) == 'iossimulator-x64' OR '$(RuntimeIdentifier)' == 'iossimulator-arm64'">$(MSBuildThisFileDirectory)..\..\runtimes\iossimulator\native\libMoltenVK.a</_LibMoltenVKPath>
<_LibMoltenVKPath Condition="'$(RuntimeIdentifier)' == 'ios-arm64'">$(MSBuildThisFileDirectory)..\..\runtimes\ios\native\libMoltenVK.a</_LibMoltenVKPath>
</PropertyGroup>

<ItemGroup>
<NativeReference Include="$(_LibMoltenVKPath)" Condition="'$(_LibMoltenVKPath)' != ''">
<Kind>Static</Kind>
<Forceload>True</Forceload>
<IsCxx>True</IsCxx>
<SmartLink>False</SmartLink>
<LinkerFlags> -framework Metal -framework IOSurface -framework UIKit -framework QuartzCore -framework CoreGraphics -framework IOKit -framework Foundation </LinkerFlags>
</NativeReference>
</ItemGroup>
</Project>
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 11 additions & 0 deletions src/Vulkan/Silk.NET.Vulkan/PreventSilkTouchBugAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;

namespace Silk.NET.Vulkan;

internal class PreventSilkTouchBugAttribute : Attribute
{

}
2 changes: 1 addition & 1 deletion src/Vulkan/Silk.NET.Vulkan/Silk.NET.Vulkan.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0;net7.0-ios;net7.0-maccatalyst</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>preview</LangVersion>
</PropertyGroup>
Expand Down
5 changes: 5 additions & 0 deletions src/Vulkan/Silk.NET.Vulkan/Vk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

namespace Silk.NET.Vulkan
{
#if __IOS__
[PInvokeOverride(0, "__Internal")]
[PInvokeOverride(1, "libVulkan.so")]
#endif
[PreventSilkTouchBug]
public partial class Vk
{
private Instance? _currentInstance;
Expand Down

0 comments on commit fdd0f40

Please sign in to comment.