Skip to content

Conversation

@karhu
Copy link

@karhu karhu commented May 22, 2025

I wanted to use Vulkan validation layers on MacOS. The changes below are what's necessary to dynamically link Vulkan from an installed Vulkan SDK.

I've moved these changes behind a new feature-flag, to keep the static linking behavior as default on MacOS.

Please take a look :)

Comment on lines +101 to +106
// Molten-vk doesn't support the full Vulkan feature set, hence the portability subset extension must be enabled.
#[cfg(all(target_os = "macos", feature = "macos-dynamic-molten-vk"))]
{
enabled_ext_names.push(khr::portability_subset::NAME.as_ptr());
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be enabled for target_os = "macos" regardless of macos-dynamic-molten-vk? Same question below for ash::khr::portability_enumeration, etc...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

@karhu karhu May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave a longer top-level comment with more details, but in short I've tried that, but it errors out at runtime when requesting those extensions, but not linking dynamically. The error states that "Vulkan Error: Extension specified does not exist."

I suspect (not verified though) this is because screen-13 defaults to using ash-molten, which in turn statically links against an outdated version of MoltenVK.

@DGriffin91
Copy link
Contributor

@karhu Would you be able to provide/link a bit of docs on how to use this feature (dynamically linking Vulkan, using Vulkan validation layers on MacOS)? If so, I would be happy to test it.

@karhu
Copy link
Author

karhu commented May 22, 2025

@DGriffin91 Thanks for taking the time to look into this. I'm far from an expert on Vulkan tbh, but I'm happy to provide some context based on my understanding:

The current version of screen-13 has different behavior on MacOS, compared to other platforms (Win, Linux, ...?).
While on most platforms it relies on dynamic linking, on MacOS it does not, and instead relies on ash-molten to statically link against Vulkan (to be specific it links against MoltenVK, a Vulkan compatibility layer on top of Metal, specific for MacOS).

Vulkan validation layers work by injecting verification logic into your application when the dynamically linked Vulkan symbols are resolved at runtime. This allows enabling/disabling them without recompiling the target binary.

The undesirable consequences of this are:

  • ash-molten statically links against a hardcoded version of MoltenVK, as of today that is 1.2.8, which at about a year old is a bit outdated, with 1.3.0 being the latest release.
  • Vulkan validation layers cannot be injected.
  • Longer compilation times, running an uncached build on MacOS takes quite a bit of time for the ash-molten dependency.
  • Differences in debugging capabilities between platforms.

On the other hand, the desirable consequences of this are:

  • No need to separately install the Vulkan SDK on your machine.
  • "cargo run ..." just works / compiles.

Check the ash-molten page, as they are pretty open about that in their project description.

@karhu
Copy link
Author

karhu commented May 22, 2025

As for testing instructions:

  • Get the VulkanSDK for MacOS from the download page linked in this article, and while at it give at least the first part of the article a read :)
  • After installing the SDK, I had a Vulkan Configurator icon in my top-left menu bar. Opening that application allows to enable /disable Vulkan validation features.
    image
  • You might (not sure) have to run a source ~/VulkanSDK/1.4.309.0/setup-env.sh in the terminal session you're using to run your rust build and run commands.
  • Lastly, pick your screen-13 based project of choice and update the dependency to link to my fork, and enabling the new feature flag, something along the lines of screen-13 = { path = "../third-party/screen-13", features = ["macos-dynamic-molten-vk"]} assuming you have it locally checked out.
  • Run the app with different validation settings, and observe how verbose the console output becomes.

@attackgoat
Copy link
Owner

attackgoat commented May 22, 2025

Thank you for those instructions - I've never taken the time to try out dynamic linking Vulkan on Mac but I definitely want the debugging layers there. Mac has always been a "best-effort" platform for what I've been doing and I would like this get merged.

I'll test on the Mac's I have access to:

  • MacBook Pro 2016 Intel HD 530 & AMD Radeon Pro 450 (Monterey 12.7.6)
  • MacBook Pro 2023 M3 Max (Sequoia 15.4)
  • Mac mini 2023 M2 (Sonoma 14.5)

@karhu
Copy link
Author

karhu commented May 25, 2025

Glad to hear!
For reference, I've been testing a similar setup as your second one:
MacBook Pro 2023 M3 Max (Sequoia 15.5), Vulkan SDK 1.4.309.0

Btw, I'm curious about your preference as to which linking behavior should be the default, and which opt-in via feature flag. I implemented it the way it is right now in order to not break any existing behavior. Defaulting to "static linking" definitely has the advantage that it is more likely to "just work". On the other hand, defaulting to dynamic linking would make the library more consistent across platforms.

@attackgoat
Copy link
Owner

Sorry for the delay, I've just now tried this and it works as described.

I would like to swap the feature flag for linked and have the same logic as Ash: default to loaded and allow linked. Really there is no reason we can't allow Ash to be statically linked on Windows/Linux.

I'll add some details to the documentation before release, too:

Vulkan SDK optional except on macOS unless using the linked feature

... but probably more wordy. The way I put that does seem super confusing.

@attackgoat
Copy link
Owner

@karhu I'll make the above changes, if that's alright with you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants