{"rsdb":{"rid":"397322","subhead":"","postdate":"0","aid":"273519","fid":"49","uid":"1","topic":"1","content":"
\n

\u539f\u672c\u4f60\u5199\u7684\u7a0b\u5e8f\u662f\u9759\u6001\u94fe\u63a5\u7684\u7cfb\u7edf\u7684vulkan-1.dll\uff0c\u5982\u679c\u7cfb\u7edf\u4e0d\u5b58\u5728vulkan-1.dll\uff0c\u5219\u4f1a\u76f4\u63a5\u5d29\u6e83\u3002<\/p> \n

\u5173\u4e8e\u5c06ncnn\u9759\u6001\u94fe\u63a5vulkan\u6539\u6210\u52a8\u6001\u52a0\u8f7dvulkan\u7684\u5f62\u5f0f\uff0c\u7136\u540e\u63d0\u4f9b\u8fd9\u4e24\u4e2a\u51fd\u6570<\/p> \n

\n
\n bool ncnn::has_vulkan();<\/span><\/span><\/span><\/span><\/span><\/span>\n <\/div> \n
\n void ncnn::use_vulkan(bool);<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\n <\/div> \n <\/div> \n

\u8bf7\u6559\u8fc7ncnn\u7684\u4f5c\u8005nihui\uff0c\u5979\u5bf9\u6b64issue\u8868\u793a\u4e0d\u4ee5\u4e3a\u610f\uff0c\u6ca1\u6709\u5fc5\u8981\uff0c\u4f18\u5148\u7ea7\u4e0d\u9ad8\u3002<\/p> \n

\u90a3\u5c31\u53ea\u6709\u81ea\u5df1\u52a8\u624b\u4e30\u8863\u8db3\u98df\u4e86\u3002<\/p> \n

\u672c\u6587\u7684\u76ee\u6807\u662f\u5c06\u5176\u6539\u4e3a\u52a8\u6001\u52a0\u8f7d\u7684\u65b9\u5f0f\uff0c\u7528\u5230\u4e86KhronosGroup\u7ec4\u7ec7\u4e0b\u7684Vulkan-SDK\u91cc\u9762\u7684CPP\u90e8\u5206\uff0c\u5373vulkan.hpp<\/p> \n

\u672c\u4eba\u7684\u4e0a\u4e00\u7bc7\u6587\u7ae0\uff08https:\/\/www.cnblogs.com\/hyb1\/p\/17361775.html<\/a>\uff09\u8bf4\u7684\u662f\u5982\u4f55\u52a8\u6001\u5224\u65ad\u662f\u5426\u5b58\u5728vulkan-1.dll\u5e76\u4e14\u518d\u52a0\u8f7d\u7684\u8fc7\u7a0b\uff0c<\/p> \n

\u4f46\u662f\u6ca1\u63d0\u5230\u5982\u4f55\u9488\u5bf9\u73b0\u6709\u7684\u9879\u76ee\u6539\u52a8\uff0c\u6bd4\u5982\u8bf4\u73b0\u5728\u7684ncnn\u542b\u6709\u7684\u5927\u91cfC Style\u7684vulkan\u51fd\u6570\u7b26\u53f7\u76f4\u63a5\u8c03\u7528\u7684\u4ee3\u7801\uff0c\u5982\u679c\u76f4\u63a5\u4fee\u6539\uff0c\u9700\u8981\u5c06\u6bcf\u4e00\u4e2avulkan\u51fd\u6570\u7684\u5730\u65b9\u90fd\u52a0\u4e00\u4e2a\u524d\u7f00\uff0c\u7c7b\u4f3c\u8fd9\u6837\uff1a<\/p> \n

mVulkanDispatchLoaderDynamic->vkCreateInstance(&instanceCreateInfo, 0, &instance);<\/p> \n

mVulkanDispatchLoaderDynamic->vkEnumeratePhysicalDevices(g_instance, &physicalDeviceCount, 0);<\/p> \n

\u8de8\u8d8a\u4e86\u5f88\u591a.cpp\u548c.h\u6587\u4ef6\uff0c\u4fee\u6539\u8d77\u6765\u76f8\u5f53\u9ebb\u70e6\uff0c\u800c\u4e14\u8fd8\u4f1a\u9047\u5230\u5168\u5c40\u53d8\u91cf\u662f\u5426\u6709\u6548\u7b49\u7b49\u95ee\u9898\u3002<\/p> \n

\u5e9f\u8bdd\u4e0d\u591a\u8bf4\uff0c\u76f4\u63a5\u8bf4\u603b\u7ed3\uff1a<\/p> \n

Vulkan Loader\u63d0\u4f9b\u4e86\u591a\u4e2a\u5b8f\u5b9a\u4e49\uff1aVULKAN_HPP_STORAGE_API\u548cVULKAN_HPP_STORAGE_SHARED\u548cVULKAN_HPP_STORAGE_SHARED_EXPORT
\u5b83\u4eec\u662fvulkan.hpp\u4e2d\u7528\u6765\u63a7\u5236vulkan\u51fd\u6570\u7684\u5b58\u50a8\u7c7b\u522b\u7684\u5b8f\u3002
VULKAN_HPP_STORAGE_API: <\/p> \n

\u8fd9\u4e2a\u5b8f\u7528\u6765\u6307\u5b9avulkan\u51fd\u6570\u7684\u5b58\u50a8\u7c7b\u522b\uff0c\u6bd4\u5982__declspec(dllexport)\u6216\u8005__declspec(dllimport)\u3002
\u8fd9\u4e2a\u5b8f\u53ef\u4ee5\u5728\u7f16\u8bd1\u65f6\u7531\u5916\u90e8\u5b9a\u4e49\uff0c\u4ee5\u4fbf\u4e8e\u5c06vulkan\u51fd\u6570\u5bfc\u51fa\u6216\u8005\u5bfc\u5165\u3002<\/p> \n


VULKAN_HPP_STORAGE_SHARED: <\/p> \n

\u8fd9\u4e2a\u5b8f\u7528\u6765\u542f\u7528\u52a8\u6001\u94fe\u63a5\u5e93\u7684\u6a21\u5f0f\uff0c\u5373\u5c06vulkan\u51fd\u6570\u4f5c\u4e3adll\u7684\u5bfc\u51fa\u6216\u8005\u5bfc\u5165\u3002
\u5982\u679c\u5b9a\u4e49\u4e86\u8fd9\u4e2a\u5b8f\uff0c\u90a3\u4e48VULKAN_HPP_STORAGE_API\u4f1a\u6839\u636eVULKAN_HPP_STORAGE_SHARED_EXPORT\u662f\u5426\u5b9a\u4e49\u6765\u81ea\u52a8\u8bbe\u7f6e\u4e3a__declspec(dllexport)\u6216\u8005__declspec(dllimport)\u3002
\u5982\u679c\u6ca1\u6709\u5b9a\u4e49\u8fd9\u4e2a\u5b8f\uff0c\u90a3\u4e48VULKAN_HPP_STORAGE_API\u4f1a\u88ab\u8bbe\u7f6e\u4e3a\u7a7a\u3002<\/p> \n


VULKAN_HPP_STORAGE_SHARED_EXPORT: <\/p> \n

\u8fd9\u4e2a\u5b8f\u7528\u6765\u63a7\u5236\u52a8\u6001\u94fe\u63a5\u5e93\u7684\u6a21\u5f0f\u4e0b\uff0cvulkan\u51fd\u6570\u662f\u4f5c\u4e3adll\u7684\u5bfc\u51fa\u8fd8\u662f\u5bfc\u5165\u3002
\u5982\u679c\u5b9a\u4e49\u4e86\u8fd9\u4e2a\u5b8f\uff0c\u90a3\u4e48VULKAN_HPP_STORAGE_API\u4f1a\u88ab\u8bbe\u7f6e\u4e3a__declspec(dllexport)\uff0c\u8868\u793avulkan\u51fd\u6570\u662fdll\u7684\u5bfc\u51fa\u3002<\/p> \n

\u5982\u679c\u6ca1\u6709\u5b9a\u4e49\u8fd9\u4e2a\u5b8f\uff0c\u90a3\u4e48VULKAN_HPP_STORAGE_API\u4f1a\u88ab\u8bbe\u7f6e\u4e3a__declspec(dllimport)\uff0c\u8868\u793avulkan\u51fd\u6570\u662fdll\u7684\u5bfc\u5165\u3002

\u5982\u679c\u4f60\u662f\u5e0c\u671b\u901a\u8fc7vk::DispatchLoaderDynamic\u52a0\u8f7d\u5230defaultDispatchLoaderDynamic\u4e4b\u540e\uff0c\u4ecd\u65e7\u6309\u7167\u9759\u6001\u94fe\u63a5\u7684\u6a21\u5f0f\u6765\u7f16\u5199\u4ee3\u7801\uff0c\u4f46\u662f\u4e0d\u662f\u94fe\u63a5\u5230\u771f\u6b63\u7684vulkan-1.dll\u4e0a\uff0c\u800c\u662f\u7531vulkan-loader\u751f\u6210\u7684\u7b26\u53f7\uff0c\u5e94\u8be5\u8fd9\u6837\u505a\uff08\u91cd\u70b9\u6765\u4e86\uff09\uff1a

1. \u5b9a\u4e49VULKAN_HPP_ENABLE_DYNAMIC_LOADER_TOOL\u548cVULKAN_HPP_DISPATCH_LOADER_DYNAMIC\u4e24\u4e2a\u5b8f\uff0c\u4ee5\u542f\u7528\u52a8\u6001\u52a0\u8f7dvulkan\u5e93\u548c\u51fd\u6570\u7684\u529f\u80fd\u3002
2. \u4e0d\u8981\u5b9a\u4e49VULKAN_HPP_STORAGE_SHARED\u548cVULKAN_HPP_STORAGE_SHARED_EXPORT\u4e24\u4e2a\u5b8f\uff0c\u4ee5\u907f\u514d\u4f7f\u7528dll\u7684\u6a21\u5f0f\u3002
3. \u4f7f\u7528vk::DynamicLoader\u7c7b\u6765\u52a8\u6001\u52a0\u8f7dvulkan-loader\u751f\u6210\u7684\u7b26\u53f7\uff0c\u5e76\u4e14\u83b7\u53d6vkGetInstanceProcAddr\u51fd\u6570\u7684\u5730\u5740\u3002
4. \u8c03\u7528VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr)\u6765\u521d\u59cb\u5316\u9ed8\u8ba4\u7684\u51fd\u6570\u6307\u9488\u5c01\u88c5\u5bf9\u8c61\u3002
5. \u4f7f\u7528\u9ed8\u8ba4\u7684\u51fd\u6570\u6307\u9488\u5c01\u88c5\u5bf9\u8c61\u6216\u8005\u81ea\u5b9a\u4e49\u7684vk::DispatchLoaderDynamic\u5bf9\u8c61\u6765\u8c03\u7528\u5176\u4ed6vulkan\u51fd\u6570\u3002

<\/p> \n

\n
#define<\/span> VULKAN_HPP_ENABLE_DYNAMIC_LOADER_TOOL 1\n#define<\/span> VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1\n\/\/<\/span>#define VULKAN_HPP_STORAGE_API 0<\/span>\n#undef<\/span> VULKAN_HPP_STORAGE_SHARED\n#undef<\/span> VULKAN_HPP_STORAGE_SHARED_EXPORT\n\n#include <\/span><vulkan\/vulkan.hpp>\n\n\/\/<\/span>\u5b9a\u4e49\u4e00\u4e2a\u5168\u5c40\u7684vk::DispatchLoaderDynamic\u5bf9\u8c61defaultDispatchLoaderDynamic<\/span>\nVULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE\n\n\n<\/span>\/\/<\/span>\u521d\u59cb\u5316\u7684\u65f6\u5019\u8fd9\u6837\u5199<\/span>\ntry<\/span>\n{\n#ifdef WIN32\n    std::<\/span>string<\/span> vulkanLibraryFilePath = "<\/span>vulkan-1.dll<\/span>"<\/span>;\n<\/span>#else<\/span> \/\/<\/span>APPLE<\/span>\n    std::<\/span>string<\/span> vulkanLibraryFilePath = diropt::CurrentPath() + "<\/span>\/Contents\/Frameworks\/libMoltenVK.dylib<\/span>"<\/span>;\n<\/span>#endif<\/span>\n    mVulkanDynamicLoader <\/span>= std::make_unique<vk::DynamicLoader>(vulkanLibraryFilePath);\n}\n<\/span>catch<\/span>(std::runtime_error ex)\n{\n    mSupportVulkan <\/span>= false<\/span>;\n    printf(<\/span>"<\/span>vk::DynamicLoader is null\\n<\/span>"<\/span>);\n    <\/span>return<\/span>;\n}\n<\/span>if<\/span>(!mVulkanDynamicLoader)\n{\n    mSupportVulkan <\/span>= false<\/span>;\n    printf(<\/span>"<\/span>mVulkanDynamicLoader is null\\n<\/span>"<\/span>);\n    <\/span>return<\/span>;\n}\nmSupportVulkan <\/span>= mVulkanDynamicLoader->success();\n<\/span>if<\/span>(!mSupportVulkan)\n{\n    mSupportVulkan <\/span>= false<\/span>;\n    printf(<\/span>"<\/span>mSupportVulkan is false\\n<\/span>"<\/span>);\n    <\/span>return","orderid":"0","title":"\u4f7f\u7528Vulkan-Loader\u5c06ncnn\u4ee3\u7801\u6539\u6210Dynamic Loader Vulkan\u7684\u5f62\u5f0f(\u4e00)","smalltitle":"","mid":"0","fname":"c++\u7f16\u7a0b\u57fa\u7840","special_id":"0","bak_id":"0","info":"0","hits":"641","pages":"2","comments":"0","posttime":"2023-09-23 15:44:04","list":"1695455044","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"\u4f7f\u7528<\/A> Vulkan-Loader<\/A> ncnn<\/A> Dynamic<\/A> Loader<\/A> Vulkan<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"112.94.1.100","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"\u4f7f\u7528Vulkan-Loader\u5c06ncnn\u4ee3\u7801\u6539\u6210Dynamic Loader Vulkan\u7684\u5f62\u5f0f","lastview":"1715492556","digg_num":"988","digg_time":"1715789158","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}