Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VkResult Error on macOS #6101

Closed
NewSkyLine-dev opened this issue Jan 20, 2023 · 10 comments
Closed

VkResult Error on macOS #6101

NewSkyLine-dev opened this issue Jan 20, 2023 · 10 comments

Comments

@NewSkyLine-dev
Copy link

I try to use ImGui on macOS (M1 Pro) with Vulkan. Vulkan is installed. When I try to run the example program example_glfw_vulkan it gives me this error:

[vulkan] Error: VkResult = -9
zsh: abort      ./example_glfw_vulkan

How could I resolve this error, or do I have to use Metal, even though Vulkan should work on Mac, shouldn't it?

@GamingMinds-DanielC
Copy link
Contributor

Error -9 is VK_ERROR_INCOMPATIBLE_DRIVER, not an ImGui issue. Your graphics driver is either not correctly installed or out of date.

@NewSkyLine-dev
Copy link
Author

NewSkyLine-dev commented Jan 20, 2023

Error -9 is VK_ERROR_INCOMPATIBLE_DRIVER, not an ImGui issue. Your graphics driver is either not correctly installed or out of date.

I'm on the newest macOS Version. And from what I know, it automatically updates with the newest updates, doesn't it? And the Vulkan examples, Cube etc. work.

@GamingMinds-DanielC
Copy link
Contributor

I don't know, I don't use macOS. But the error you get clearly points to an issue in your driver version or setup (assuming that the GPU part of the M1 Pro supports Vulkan).

@NewSkyLine-dev
Copy link
Author

NewSkyLine-dev commented Jan 20, 2023

I have read some documentation, and look like this error is new in VulkanSDK 1.3.216 when using macOS. It's now mandatory to use the VK_KHR_PORTABILITY_subset extension.
Reading the Vulkan Documents, it's mentioned with a short paragraph:

Encountered VK_ERROR_INCOMPATIBLE_DRIVER:

Beginning with the 1.3.216 Vulkan SDK, the Vulkan Loader is strictly enforcing the new VK_KHR_PORTABILITY_subset extension. The most likely cause of this error message on instance creation is failure to adhear to this extension, which prevents applications on all platforms from selecting by default a non-conformant Vulkan implementaton without opting in. MoltenVK is currently not fully conformant, and thus supporting this extension is necessary for building robust and portable Vulkan based applications that are good citizens in the Vulkan ecosystem.
Opting in is simple. First add the VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR bit to your VkInstanceCreateInfo structures .flags member, then add two instance extensions to your instance extensions list: VK_KHR_portability_enumeration, and VK_KHR_get_physical_device_properties2.

If I get it to work, I will make a Pull-Request, maybe? Don't know if it's necessary… Will make my next comment, when I tried…
Fixes are still very welcome :)

@ocornut
Copy link
Owner

ocornut commented Jan 20, 2023

Thanks for investigating. Yes, a detailed report and fix (either as comment here, or better as a PR) would be greatly welcome!

One thing to be mindful of is that it is probable that the 3 listed symbols are recent additions to Vulkan headers, and therefore the new additions would need to be guarded by compile-time #if statement.

Something like:

#if VK_HEADER_VERSION_COMPLETE >= VK_MAKE_API_VERSION(0, 1, 3, 216)
#define VULKAN_HAS_KHR_PORTABILITY
#endif

...

#ifdef VULKAN_HAS_KHR_PORTABILITY
// extra code
#endif

(That's untested, and not 100% if it the correct way to do a compile-time Vulkan SDK check but it seems like it!)

@zao
Copy link

zao commented Jan 21, 2023

Did some drive-by testing as I had a machine handy and it doesn't seem to be quite compile-time enough:

/Users/zao/dep/imgui/examples/example_glfw_vulkan/main.cpp:36:5: error: token is not a valid binary operator in a preprocessor subexpression
#if VK_HEADER_VERSION_COMPLETE >= VK_MAKE_API_VERSION(0, 1, 3, 216)
    ^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/vulkan/vulkan_core.h:78:36: note: expanded from macro 'VK_HEADER_VERSION_COMPLETE'
#define VK_HEADER_VERSION_COMPLETE VK_MAKE_API_VERSION(0, 1, 3, VK_HEADER_VERSION)
                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/vulkan/vulkan_core.h:69:18: note: expanded from macro 'VK_MAKE_API_VERSION'
    ((((uint32_t)(variant)) << 29) | (((uint32_t)(major)) << 22) | (((uint32_t)(minor)) << 12) | ((uint32_t)(patch)))
       ~~~~~~~~~~^
1 error generated.

On the plus side of things, ignoring the above problem and unconditionally adding the instance extensions and flag to the createInfo as suggested makes the sample run on my M1 Mini.

Tested with SDK versions 1.3.204.1, 1.3.211.0 and 1.3.236.0. Notable is that the extension is already available in .211 so for full testing of detection logic the .204 SDK should probably be considered as it's absent back then.

@NewSkyLine-dev
Copy link
Author

NewSkyLine-dev commented Jan 21, 2023

Got it to work. Only added

create_info.flags = VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;

VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME and VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME to the extensions array. Maybe it's a good idea to change the const char **extensions to a std::vector<const char*>, if they decide to add another dependencie in the future. Will make a PR when I added an if for checking the Vulkan version, and maybe change it to a vector.

@NewSkyLine-dev
Copy link
Author

Added PR #6109

@NewSkyLine-dev
Copy link
Author

Closing this issue, because of the Pull-Request #6109.

ocornut added a commit that referenced this issue Apr 13, 2023
…dation layer errors. (#6109, #6172, #6101)

Enable VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME, VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR
ocornut added a commit that referenced this issue Apr 13, 2023
kjblanchard pushed a commit to kjblanchard/imgui that referenced this issue May 5, 2023
…dation layer errors. (ocornut#6109, ocornut#6172, ocornut#6101)

Enable VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME, VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR
kjblanchard pushed a commit to kjblanchard/imgui that referenced this issue May 5, 2023
@Anaphylaxis
Copy link

Getting this with imgui docking -- VkResult = -9 and abort, unless I use sudo in which case it runs fine
glfw commit b35641f4a3c62aa86a0b3c983d163bc0fe36026d
vulkan sdk 1.3.283.0

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

No branches or pull requests

5 participants