Skip to content

Commit e6996cb

Browse files
committed
Append new section in Instance create chapter
append new section showing how to fix `VK_ERROR_INCOMPATIBLE_DRIVER` with latest MoltenVK sdk
1 parent dcfd879 commit e6996cb

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

en/03_Drawing_a_triangle/00_Setup/01_Instance.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,37 @@ if (vkCreateInstance(&createInfo, nullptr, &instance) != VK_SUCCESS) {
109109

110110
Now run the program to make sure that the instance is created successfully.
111111

112+
## Encountered VK_ERROR_INCOMPATIBLE_DRIVER:
113+
If using MacOS with the latest MoltenVK sdk, you may get `VK_ERROR_INCOMPATIBLE_DRIVER`
114+
returned from `vkCreateInstance`. Accroding to the [Getting Start Notes](https://vulkan.lunarg.com/doc/sdk/1.3.216.0/mac/getting_started.html). Beginning with the 1.3.216 Vulkan SDK, the `VK_KHR_PORTABILITY_subset`
115+
extension is mandatory.
116+
117+
To get over this error, first add the `VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR` bit
118+
to `VkInstanceCreateInfo` struct's flags, then add `VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME`
119+
to instance enabled extension list.
120+
121+
Typically the code could be like this:
122+
```c++
123+
...
124+
125+
std::vector<const char*> requiredExtensions;
126+
127+
for(uint32_t i = 0; i < glfwExtensionCount; i++) {
128+
requiredExtensions.emplace_back(glfwExtensions[i]);
129+
}
130+
131+
requiredExtensions.emplace_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME)
132+
133+
createInfo.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
134+
135+
createInfo.enabledExtensionCount = (uint32_t) requiredExtensions.size();
136+
createInfo.ppEnabledExtensionNames = requiredExtensions.data();
137+
138+
if (vkCreateInstance(&createInfo, nullptr, &instance) != VK_SUCCESS) {
139+
throw std::runtime_error("failed to create instance!");
140+
}
141+
```
142+
112143
## Checking for extension support
113144

114145
If you look at the `vkCreateInstance` documentation then you'll see that one of

0 commit comments

Comments
 (0)