-
Notifications
You must be signed in to change notification settings - Fork 4.4k
dynamic vulkan loading on apple platforms, honor VK_DRIVER_FILES env #6499
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
Changes from 2 commits
192f33f
211c927
9845873
edd8a0d
3902b3d
de22379
e2b7280
117442d
372d5e2
e4d0853
2700267
effe5d8
96b8aae
293d16f
42bbeb2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -27,10 +27,8 @@ | |||||||
| #endif | ||||||||
|
|
||||||||
| #if __APPLE__ | ||||||||
|
|
||||||||
| // always use static vulkan linkage on apple platform | ||||||||
| // static vulkan linkage on apple platform as fallback | ||||||||
| extern "C" VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* pName); | ||||||||
|
|
||||||||
| #endif | ||||||||
|
|
||||||||
| namespace ncnn { | ||||||||
|
|
@@ -43,28 +41,78 @@ PFN_vkEnumerateInstanceExtensionProperties vkEnumerateInstanceExtensionPropertie | |||||||
| PFN_vkCreateInstance vkCreateInstance = 0; | ||||||||
| PFN_vkEnumerateInstanceLayerProperties vkEnumerateInstanceLayerProperties = 0; | ||||||||
|
|
||||||||
| #if __APPLE__ | ||||||||
|
|
||||||||
| int load_vulkan_driver(const char* /*driver_path*/) | ||||||||
| static std::string get_driver_path_from_icd(const char* icd_path) | ||||||||
| { | ||||||||
| unload_vulkan_driver(); | ||||||||
| FILE* fp = fopen(icd_path, "rb"); | ||||||||
| if (!fp) | ||||||||
| return std::string(); | ||||||||
|
|
||||||||
| vkGetInstanceProcAddr = ::vkGetInstanceProcAddr; | ||||||||
| vkEnumerateInstanceExtensionProperties = (PFN_vkEnumerateInstanceExtensionProperties)vkGetInstanceProcAddr(NULL, "vkEnumerateInstanceExtensionProperties"); | ||||||||
| vkCreateInstance = (PFN_vkCreateInstance)vkGetInstanceProcAddr(NULL, "vkCreateInstance"); | ||||||||
| vkEnumerateInstanceLayerProperties = (PFN_vkEnumerateInstanceLayerProperties)vkGetInstanceProcAddr(NULL, "vkEnumerateInstanceLayerProperties"); | ||||||||
| return 0; | ||||||||
| std::string driver_path; | ||||||||
|
|
||||||||
| char line[256]; | ||||||||
| while (!feof(fp)) | ||||||||
| { | ||||||||
| char* s = fgets(line, 256, fp); | ||||||||
| if (!s) | ||||||||
| break; | ||||||||
|
|
||||||||
| // "library_path": "path to driver library", | ||||||||
| char path[256]; | ||||||||
| int nscan = sscanf(line, " \"library_path\" : \"%255[^\"]\"", path); | ||||||||
nihui marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+52
to
+61
|
||||||||
| if (nscan == 1) | ||||||||
| { | ||||||||
| if (path[0] == '.' || (path[0] != '/' && !strchr(path, ':') && (strchr(path, '/') || strchr(path, '\\')))) | ||||||||
|
||||||||
| if (path[0] == '.' || (path[0] != '/' && !strchr(path, ':') && (strchr(path, '/') || strchr(path, '\\')))) | |
| bool is_absolute = (path[0] == '/' || path[0] == '\\' || strchr(path, ':')); | |
| if (!is_absolute) |
nihui marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The well-known path entry "libvulkan_kosmickrisp.dylib" appears to be a non-standard or test/development library name. If this is a legitimate Vulkan implementation, it should be documented. If it's for testing purposes only, consider adding a comment explaining its purpose. The unusual name "kosmickrisp" may confuse future maintainers.
| "libMoltenVK.dylib", | |
| "libMoltenVK.dylib", | |
| // Non-standard/internal Vulkan implementation used as an additional fallback on Apple platforms. |
Uh oh!
There was an error while loading. Please reload this page.