aclysma / skulpin

Skia + Vulkan = Skulpin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot create instance on M1 Mac with MoltenVK

samizdatco opened this issue · comments

I've run into problems getting Skulpin to run on macOS. As far as I can tell, my installation of MoltenVK is working (for instance, the ash and vulkano crates’ examples manage to open windows and render correctly):

❯ cargo run --example interactive_winit_app --features winit-app,winit-25
    Finished dev [unoptimized + debuginfo] target(s) in 0.24s
     Running `target/debug/examples/interactive_winit_app`
[2022-07-22T15:03:49Z INFO  rafx_api::backends::vulkan::api] Validation mode: Disabled
[2022-07-22T15:03:49Z INFO  rafx_api::backends::vulkan::api] Link method for vulkan: Dynamic
[2022-07-22T15:03:49Z INFO  rafx_api::backends::vulkan::internal::instance] Found Vulkan version: (1, 3, 216)
[2022-07-22T15:03:49Z DEBUG rafx_api::backends::vulkan::internal::instance] Available Layers: [
    LayerProperties {
        layer_name: "VK_LAYER_LUNARG_api_dump",
        spec_version: 4206808,
        implementation_version: 2,
        description: "LunarG API dump layer",
    },
    LayerProperties {
        layer_name: "VK_LAYER_KHRONOS_profiles",
        spec_version: 4206808,
        implementation_version: 1,
        description: "Khronos Profiles layer",
    },
    LayerProperties {
        layer_name: "VK_LAYER_KHRONOS_validation",
        spec_version: 4206808,
        implementation_version: 1,
        description: "Khronos Validation Layer",
    },
    LayerProperties {
        layer_name: "VK_LAYER_KHRONOS_synchronization2",
        spec_version: 4206808,
        implementation_version: 1,
        description: "Khronos Synchronization2 layer",
    },
]
[2022-07-22T15:03:49Z DEBUG rafx_api::backends::vulkan::internal::instance] Available Extensions: [
    ExtensionProperties {
        extension_name: "VK_KHR_device_group_creation",
        spec_version: 1,
    },
    ExtensionProperties {
        extension_name: "VK_KHR_external_fence_capabilities",
        spec_version: 1,
    },
    ExtensionProperties {
        extension_name: "VK_KHR_external_memory_capabilities",
        spec_version: 1,
    },
    ExtensionProperties {
        extension_name: "VK_KHR_external_semaphore_capabilities",
        spec_version: 1,
    },
    ExtensionProperties {
        extension_name: "VK_KHR_get_physical_device_properties2",
        spec_version: 2,
    },
    ExtensionProperties {
        extension_name: "VK_KHR_get_surface_capabilities2",
        spec_version: 1,
    },
    ExtensionProperties {
        extension_name: "VK_KHR_surface",
        spec_version: 25,
    },
    ExtensionProperties {
        extension_name: "VK_EXT_debug_report",
        spec_version: 10,
    },
    ExtensionProperties {
        extension_name: "VK_EXT_debug_utils",
        spec_version: 2,
    },
    ExtensionProperties {
        extension_name: "VK_EXT_metal_surface",
        spec_version: 1,
    },
    ExtensionProperties {
        extension_name: "VK_EXT_swapchain_colorspace",
        spec_version: 4,
    },
    ExtensionProperties {
        extension_name: "VK_MVK_macos_surface",
        spec_version: 3,
    },
    ExtensionProperties {
        extension_name: "VK_KHR_portability_enumeration",
        spec_version: 1,
    },
]
[2022-07-22T15:03:49Z DEBUG rafx_api::backends::vulkan::internal::instance] Using layers: []
[2022-07-22T15:03:49Z DEBUG rafx_api::backends::vulkan::internal::instance] Using extensions: ["VK_KHR_surface", "VK_EXT_metal_surface"]
[2022-07-22T15:03:49Z INFO  rafx_api::backends::vulkan::internal::instance] Creating vulkan instance
[2022-07-22T15:03:49Z WARN  skulpin_app_winit::app] Passing RendererBuilder::build() error to app Unable to find a Vulkan driver
Unable to find a Vulkan driver

Perhaps the more direct approach is to use Metal on the Mac, but it would still be nice to maintain compatibility with MoltenVK in order to test Vulkan code intended for use on other platforms.

This used to work for me on an M1 mac not that long ago. Downgrading to an older moltenvk might fix the problem. I can double check what version was working for me when I tried it last.

(This isn’t a good solution but if it works it may, in addition to being a workaround, shed some light on why it doesn’t work. I’m suspicious that moltenvk returning 1.3 makes skia take a less well-tested codepath.)

Hi @aclysma

I'm having this problem too now.

I think this will fix it:

https://stackoverflow.com/a/73408303/1901658

As of Vulkan SDK 1.3.216, we also must enable the VK_KHR_portability_enumeration extension, and set the VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR flag when creating the instance, in order to use MoltenVK. Without this, I've observed that the loader will return VK_ERROR_INCOMPATIBLE_DRIVER.

Does that seem right to you?

I've looked more into it. This seems to be a major problem:

https://github.com/aclysma/rafx/blob/a274b82c873c0ec7f9d6c3376cd054bfccfe3895/rafx-api/src/backends/vulkan/api.rs#L51

This could very well be a bug in aclysma/rafx and not skulpin.

Looks like a breaking change in the vulkan SDK that they introduced with 1.3. While I'm not maintaining this library anymore, I do want to add compatibility for the 1.3 SDK in rafx-api.

In the meantime, I would just roll back to a 1.2 SDK. I doubt there's any practical benefit to a project using skulpin to be on 1.3. I'm going to close this bug but I'll address it in the bug opened on rafx-api.

While I'm not maintaining this library anymore

That's no problem :-)

If you'd like to link to MFEK/skulpin.rlib that's an option as I plan to maintain Skulpin essentially in perpetuity. 👍