From f36906df6c4afd16591a85648d385350675a96d6 Mon Sep 17 00:00:00 2001 From: Roman Rihter Date: Tue, 10 Jun 2025 03:00:31 +0300 Subject: [PATCH 1/3] Add portability enum --- src/vk/Enums.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/vk/Enums.cs diff --git a/src/vk/Enums.cs b/src/vk/Enums.cs new file mode 100644 index 0000000..26ce96a --- /dev/null +++ b/src/vk/Enums.cs @@ -0,0 +1,16 @@ +namespace Vulkan +{ + public enum VkInstanceCreateFlagBits: uint { + /// + /// Provided by VK_KHR_portability_enumeration. Specifies that the instance will enumerate + /// available Vulkan Portability-compliant physical devices and groups in addition to the + /// Vulkan physical devices and groups that are enumerated by default. + /// + PortabilityBitKHR = 1, + }; + + public static partial class RawConstants + { + public const VkInstanceCreateFlagBits VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR = VkInstanceCreateFlagBits.PortabilityBitKHR; + }; +} From c87618f2abcb37838122f0e8faba6ca083669088 Mon Sep 17 00:00:00 2001 From: Roman Rihter Date: Tue, 10 Jun 2025 03:01:26 +0300 Subject: [PATCH 2/3] Use libMoltenVK on macOS --- src/vk/Commands.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/vk/Commands.cs b/src/vk/Commands.cs index 7583757..ca8c2b4 100644 --- a/src/vk/Commands.cs +++ b/src/vk/Commands.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; @@ -47,7 +47,9 @@ private static string GetVulkanName() #endif else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { - return "libvulkan.dylib"; + // libvulkan.dylib is an additional translation layer from Vulkan SDK. + // libMoltenVK supports libvulkan functions already. + return "libMoltenVK.dylib"; } else { From ef1d8a217d0443497ea7f26f443b153a979b3d8e Mon Sep 17 00:00:00 2001 From: Roman Rihter Date: Tue, 10 Jun 2025 03:01:54 +0300 Subject: [PATCH 3/3] Try to load MoltenVK from Homebrew on macOS --- src/vk/Commands.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/vk/Commands.cs b/src/vk/Commands.cs index ca8c2b4..e98f30d 100644 --- a/src/vk/Commands.cs +++ b/src/vk/Commands.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; @@ -162,6 +162,18 @@ protected override IntPtr LoadLibrary(string libraryName) string localPath = Path.Combine(baseDir, libraryName); handle = Libdl.dlopen(localPath, Libdl.RTLD_NOW); } + + if (handle == IntPtr.Zero && RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { + // Try to load system-wide MoltenVK from /usr/local/lib or /opt/homebrew/lib. + // It is not possible to install MoltenVK under /usr/lib on macOS due to System Integrity Protection. + string localPath = Path.Combine("/opt/homebrew/lib", libraryName); + handle = Libdl.dlopen(localPath, Libdl.RTLD_NOW); + + if (handle == IntPtr.Zero) { + localPath = Path.Combine("/usr/local/lib", libraryName); + handle = Libdl.dlopen(localPath, Libdl.RTLD_NOW); + } + } } return handle;