KhronosGroup / MoltenVK

MoltenVK is a Vulkan Portability implementation. It layers a subset of the high-performance, industry-standard Vulkan graphics and compute API over Apple's Metal graphics framework, enabling Vulkan applications to run on macOS, iOS and tvOS.
Apache License 2.0
4.64k stars 402 forks source link

ver 1.3.280.0 failed for 'VK_ERROR_INCOMPATIBLE_DRIVER' on macOS 14.3.1 #2192

Closed CheneyER08 closed 3 months ago

CheneyER08 commented 3 months ago

OS: macOS 14.3.1 GPU: Apple Silicon M1 Max Vulkan SDK: 1.3.280.0

It works well on my Windows PC. On macOS, it build successfully, but execute failed for VK_ERROR_INCOMPATIBLE_DRIVER while creating VkInstance. I have tried Cmake and Xcode projects.

Below is my CMakeLists.txt

cmake_minimum_required(VERSION 3.27)
project(Tutorials LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
if (NOT DEFINED ENV{VULKAN_SDK})
        set(ENV{VULKAN_SDK} "/Users/cheneyshue/VulkanSDK/1.3.280.0/macOS")
        set(ENV{VK_ICD_FILENAMES} "$ENV{VULKAN_SDK}/share/vulkan/icd.d/MoltenVK_icd.json")
        set(ENV{VK_LAYER_PATH} "$ENV{VULKAN_SDK}/share/vulkan/explicit_layer.d")
        include_directories("$ENV{VULKAN_SDK}/include")
        find_library(VulkanLib NAMES vulkan PATHS "$ENV{VULKAN_SDK}/lib")
endif ()
add_executable(Tutorials main.cpp
        VulkanApp.cpp
        VulkanApp.h)
target_link_libraries(Tutorials ${VulkanLib})

Below is my code to create VkInstance

    VkApplicationInfo appInfo {
            .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
            .pApplicationName = "Vulkan Tutorials",
            .applicationVersion = VK_MAKE_VERSION(1, 0, 0),
            .pEngineName = "No Engine",
            .engineVersion = VK_MAKE_VERSION(1, 0, 0),
            .apiVersion = VK_API_VERSION_1_0
    };
    VkInstanceCreateInfo createInfo {
            .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
            .flags = VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR,
            .pApplicationInfo = &appInfo,
            .enabledLayerCount = 0,
            .ppEnabledLayerNames = {},
            .enabledExtensionCount = 0,
            .ppEnabledExtensionNames = {}
    };

    VkResult result = vkCreateInstance(&createInfo, nullptr, &instance);

Below is the statements to execute built binary.

source /Users/cheneyshue/VulkanSDK/1.3.280.0/setup-env.sh
./Tutorials

BTW, the vkcube and vulkanCapsViewer can execute well on my macOS.

richard-lunarg commented 3 months ago

You are missing the portability instance extension required on macOs. Some recommended reading here that will help smooth the way for you: https://www.lunarg.com/news-insights/white-papers/the-state-of-vulkan-on-apple-devices-updated/

CheneyER08 commented 3 months ago

You are missing the portability instance extension required on macOs. Some recommended reading here that will help smooth the way for you: https://www.lunarg.com/news-insights/white-papers/the-state-of-vulkan-on-apple-devices-updated/

Thanks. It works after add portability extension.

rgaufman commented 1 month ago

I fixed the problem by installing molten-vk with:

brew install molten-vk

Thank you for the heads up!