SilkVulkanTutorial icon indicating copy to clipboard operation
SilkVulkanTutorial copied to clipboard

Add osx (m1) support

Open mcdis opened this issue 2 years ago • 2 comments

At this moment the samples crashed on m1, but original examples from VulkanSDK with MoltenVK are work fine

mcdis avatar Jan 20 '23 23:01 mcdis

For anyone with this issue, I found a fix. On M1 you need to set it up so that vulkan operates in a portability mode that is compatible with molten. Change the following function in each of the projects.

    private string[] GetRequiredExtensions()
    {
        var glfwExtensions = window!.VkSurface!.GetRequiredExtensions(out var glfwExtensionCount);
        var extensions = SilkMarshal.PtrToStringArray((nint)glfwExtensions, (int)glfwExtensionCount);
        extensions = extensions.Append("VK_KHR_portability_enumeration").ToArray();
        if (EnableValidationLayers)
        {
            return extensions.Append(ExtDebugUtils.ExtensionName).ToArray();
        }

        return extensions;
    }

and then the place where it's called, you need to add the createInfo.Flags bit

        var extensions = GetRequiredExtensions();
        createInfo.EnabledExtensionCount = (uint)extensions.Length;
        createInfo.PpEnabledExtensionNames = (byte**)SilkMarshal.StringArrayToPtr(extensions); ;
        createInfo.Flags = InstanceCreateFlags.EnumeratePortabilityBitKhr;

After that, it all works.

jessdecker avatar Sep 06 '23 23:09 jessdecker

Works well. Thanks!

P7AC1D avatar Apr 25 '24 05:04 P7AC1D