侧边栏壁纸
博主头像
wxc博主等级

多接近生活,远离互联网

  • 累计撰写 49 篇文章
  • 累计创建 3 个标签
  • 累计收到 0 条评论
标签搜索

目 录CONTENT

文章目录
mac

vulkan在mac上的vk::createInstance: ErrorIncompatibleDriver问题解决方法

wxc
wxc
2023-03-04 / 0 评论 / 0 点赞 / 392 阅读 / 283 字

启用VK_KHR_portability_enumeration 实例扩展
为您的实例创建信息添加(或设置)VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR 标志
启用VK_KHR_portability_subset 设备扩展

vk::Instance Context::createInstance(const std::vector<const char*>& instanceExtends)
{
    ::std::vector<const char*> layers{"VK_LAYER_KHRONOS_validation"};
    ::std::vector<const char*> externs = {instanceExtends.begin(), instanceExtends.end()};
#if defined(VK_USE_PLATFORM_MACOS_MVK)
    externs.push_back("VK_KHR_portability_enumeration");
    ::vk::InstanceCreateFlags flags{VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR};
#endif
 
    ::vk::InstanceCreateInfo createInfo;
    ::vk::ApplicationInfo appInfo;
     appInfo.setApiVersion(VK_API_VERSION_1_3);
     createInfo.setPEnabledLayerNames(layers)
                .setPApplicationInfo(&appInfo)
#if defined(VK_USE_PLATFORM_MACOS_MVK)
                .setFlags(flags)
#endif
                .setPEnabledExtensionNames(externs);
    return ::vk::createInstance(createInfo);
}

void Device::createDevice()
{
    queryQueueFamilyIndices();
    ::vk::DeviceCreateInfo createInfo;
    ::std::vector<::vk::DeviceQueueCreateInfo> queueInfos;
    // "VK_KHR_portability_subset" macos
    
#if defined(VK_USE_PLATFORM_MACOS_MVK)
   ::std::vector<const char*> extends{VK_KHR_SWAPCHAIN_EXTENSION_NAME, "VK_KHR_portability_subset"};
#else
    ::std::vector<const char*> extends{VK_KHR_SWAPCHAIN_EXTENSION_NAME};
#endif

    float priorities = 0.5;
    uint32_t queueCount = 1;
    ::vk::DeviceQueueCreateInfo queueInfo;
    queueInfo.setPQueuePriorities(&priorities)
            .setQueueCount(1)
            .setQueueFamilyIndex(queueFamilyIndices.graphicsQueue.value());
    queueInfos.push_back(::std::move(queueInfo));

    if(queueFamilyIndices.graphicsQueue.value() != queueFamilyIndices.presentQueue.value()){
        ::vk::DeviceQueueCreateInfo queueInfo;
        queueInfo.setPQueuePriorities(&priorities)
                .setQueueCount(queueCount)
                .setQueueFamilyIndex(queueFamilyIndices.presentQueue.value());
        queueInfos.push_back(::std::move(queueInfo));
    }


    createInfo.setQueueCreateInfos(queueInfos)
                .setPEnabledExtensionNames(extends);

    device = phyDevice.createDevice(createInfo);
}

编译的时候加上宏定义VK_USE_PLATFORM_MACOS_MVK即可

0

评论区